Commit Graph
58 Commits
Author SHA1 Message Date
Edy Silva 961554c89d src,sqlite: refactor value conversion
PR-URL: https://github.com/nodejs/node/pull/59659
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2025-09-02 02:57:19 +00:00
Michaël Zasso 45a8b5503e src: use non-deprecated Get/SetPrototype methods
Refs: https://github.com/v8/v8/commit/5e139e98d1e4d8bbcccf7b15cd8e7d08b28e4a81
PR-URL: https://github.com/nodejs/node/pull/59671
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Vladimir Morozov <vmorozov@microsoft.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2025-08-31 20:17:31 +00:00
Alex Yang d1eabcb044 sqlite: add sqlite-type symbol for DatabaseSync
PR-URL: https://github.com/nodejs/node/pull/59405
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
2025-08-23 21:45:43 +00:00
Edy Silva 3c1521cfa0 sqlite: handle ?NNN parameters as positional
PR-URL: https://github.com/nodejs/node/pull/59350
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2025-08-22 12:56:58 +00:00
Tobias Nießen d36941d65d sqlite: avoid useless call to FromMaybe()
PR-URL: https://github.com/nodejs/node/pull/59490
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
2025-08-18 10:26:41 +00:00
Miguel Marcondes Filho d08513dfc7 sqlite: add support for readBigInts option in db connection level
PR-URL: https://github.com/nodejs/node/pull/58697
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
2025-06-24 14:26:07 +00:00
James M Snell 62ba6196d4 sqlite: cleanup ERM support and export Session class
Update sqlite Session to support Symbol.dispose and
move the definition of the dispose methods to c++ to
close the open TODO

PR-URL: https://github.com/nodejs/node/pull/58378
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2025-05-30 17:21:30 -07:00
Colin Ihrig e201299011 sqlite: handle thrown errors in result callback
This commit updates the aggregate function 'result' callback
handling to not crash when an exception is thrown.

Fixes: https://github.com/nodejs/node/issues/58425
PR-URL: https://github.com/nodejs/node/pull/58426
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2025-05-25 21:49:37 +00:00
James M Snell 33505d1bb0 src: make a number of minor improvements to buffer
When using Buffer::New with an externally allocated buffer and
v8 sandbox enabled, defer to copy instead of wrapping the buffer.

Also, when immediately memcpy'ing into the full buffer, allocate
the buffer with kUninitialized as a slight perf optimization.

PR-URL: https://github.com/nodejs/node/pull/58377
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Daeyeon Jeong <daeyeon.dev@gmail.com>
2025-05-24 14:11:22 -07:00
Livia Medeiros 770be2c79e sqlite: set name and length on sqlite.backup()
PR-URL: https://github.com/nodejs/node/pull/58251
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2025-05-11 16:11:28 +00:00
Jonas 68cc1c9cd3 src: add dcheck_eq for Object::New constructor calls
PR-URL: https://github.com/nodejs/node/pull/57943
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-04-22 19:21:15 +00:00
Edy Silva e9b286ca4b sqlite: add location method
PR-URL: https://github.com/nodejs/node/pull/57860
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-04-21 14:57:15 +00:00
Colin Ihrig 2e0ec72f54 sqlite: add getter to detect transactions
This commit adds an isTransaction getter to the DatabaseSync
class for determining if the database is currently within a
transaction.

Fixes: https://github.com/nodejs/node/issues/57922
PR-URL: https://github.com/nodejs/node/pull/57925
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2025-04-20 15:57:42 +00:00
Edy Silva 63640eb32d src: fix typo in comments
PR-URL: https://github.com/nodejs/node/pull/57868
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Qingyu Deng <i@ayase-lab.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2025-04-19 09:33:47 +00:00
Edy Silva 62426a79ee sqlite: add timeout options to DatabaseSync
PR-URL: https://github.com/nodejs/node/pull/57752
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-04-12 16:23:01 +00:00
Chengzhong Wu f692878dec src: add BaseObjectPtr nullptr operations
Allow comparing a `BaseObjectPtr` or implicitly construct a
`BaseObjectPtr` with `nullptr`.

PR-URL: https://github.com/nodejs/node/pull/56585
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2025-04-10 16:25:10 +00:00
Edy Silva 437c6aac16 sqlite,doc,test: add aggregate function
PR-URL: https://github.com/nodejs/node/pull/56600
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-04-09 02:49:42 +00:00
Gürgün Dayıoğlu 054371dc90 sqlite: add setReturnArrays method to StatementSync
PR-URL: https://github.com/nodejs/node/pull/57542
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-04-04 21:26:52 +00:00
Edy Silva 8360ce2abf sqlite,src: refactor sqlite value conversion
PR-URL: https://github.com/nodejs/node/pull/57571
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2025-04-03 15:18:06 +00:00
Colin Ihrig 771b6829e6 sqlite: refactor prepared statement iterator
This commit refactors the StatementSync iterator implementation
in two primary ways:

- The iterator internal state is no longer exposed to JavaScript.
- The iterator prevents the prepared statement from being GC'ed.

Fixes: https://github.com/nodejs/node/issues/57493
PR-URL: https://github.com/nodejs/node/pull/57569
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2025-04-03 14:16:24 +00:00
Colin Ihrig ffc1cf6205 sqlite: add support for unknown named parameters
This commit adds a method for toggling support for unknown named
parameters in prepared statements.

Fixes: https://github.com/nodejs/node/issues/55533
PR-URL: https://github.com/nodejs/node/pull/57552
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-03-22 01:38:34 +00:00
Colin Ihrig 9851388468 sqlite: add DatabaseSync.prototype.isOpen
This commit adds a getter to indicate whether or not the database
is currently open.

Fixes: https://github.com/nodejs/node/issues/57521
PR-URL: https://github.com/nodejs/node/pull/57522
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2025-03-19 17:01:16 +00:00
Colin Ihrig 1de917b0f7 sqlite: add StatementSync.prototype.columns()
This commit adds a method for retrieving column metadata from
a prepared statement.

Fixes: https://github.com/nodejs/node/issues/57457
PR-URL: https://github.com/nodejs/node/pull/57490
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
2025-03-18 13:22:32 +00:00
Colin Ihrig a446e3bdc9 sqlite: reset statement immediately in run()
This commit updates StatementSync.prototype.run() to reset the
prepared statement immediately after calling sqlite3_step() to
return the correct change metadata.

Fixes: https://github.com/nodejs/node/issues/57344
PR-URL: https://github.com/nodejs/node/pull/57350
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
2025-03-11 00:33:27 +00:00
James M Snell 157b36b91b src: make even more improvements to error handling
PR-URL: https://github.com/nodejs/node/pull/57264
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2025-03-05 07:34:37 -08:00
Yagiz Nizipli f4dd4bb2b3 src: reduce string allocations on sqlite
PR-URL: https://github.com/nodejs/node/pull/57227
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
2025-03-01 21:00:17 +00:00
Edy Silva c7cf6778c7 sqlite,test,doc: allow Buffer and URL as database location
PR-URL: https://github.com/nodejs/node/pull/56991
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-02-27 17:43:13 +00:00
Colin Ihrig 72e1a8fbcc sqlite: fix coverity warnings related to backup()
This commit fixes several coverity warnings related to the
recently landed backup() API.

PR-URL: https://github.com/nodejs/node/pull/56961
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-02-10 18:27:01 +00:00
Colin Ihrig 1671921c4d sqlite: restore changes from #55373
PR #55373 introduced a performance improvement for the all()
method of prepared statements. Those changes appear to have been
accidentally overwritten in #54181. This change restores the
overwritten code.

Refs: https://github.com/nodejs/node/pull/55373
Refs: https://github.com/nodejs/node/pull/54181
PR-URL: https://github.com/nodejs/node/pull/56908
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2025-02-06 04:12:14 +00:00
Edy Silva 16dc29d4b6 sqlite, test: expose sqlite online backup api
PR-URL: https://github.com/nodejs/node/pull/56253
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
2025-02-05 22:26:28 +00:00
James M Snell a5cc976254 src: improve error handling in node_sqlite
PR-URL: https://github.com/nodejs/node/pull/56891
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2025-02-05 07:44:25 -08:00
Divy Srivastava cebf4c8a9f sqlite: fix use-after-free in StatementSync due to premature GC
PR-URL: https://github.com/nodejs/node/pull/56840
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-02-05 14:33:59 +00:00
Colin Ihrig c4fb331390 sqlite: handle conflicting SQLite and JS errors
This commit adds support for the situation where SQLite is
trying to report an error while JavaScript already has an
exception pending.

Fixes: https://github.com/nodejs/node/issues/56772
PR-URL: https://github.com/nodejs/node/pull/56787
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
2025-02-04 13:58:33 +00:00
René 2bd5694cd1 sqlite: allow returning ArrayBufferViews from user-defined functions
PR-URL: https://github.com/nodejs/node/pull/56790
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2025-02-01 21:19:54 +00:00
James M Snell 7b472fdfe7 src: minor cleanups on OneByteString usage
* Provide a OneByteString variant that accepts std::string_view
* Use FIXED_ONE_BYTE_STRING in appropriate places

Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/56482
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Ethan Arrowood <ethan@arrowood.dev>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
2025-01-08 06:54:39 -08:00
Alex YangandAntoine du Hamel 08b7d38aa4 sqlite: support TypedArray and DataView in StatementSync
Co-authored-by: Antoine du Hamel <duhamelantoine1995@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/56385
Fixes: https://github.com/nodejs/node/issues/56384
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2025-01-05 11:18:36 +00:00
Bart Louwers 0dbbabab95 sqlite: pass conflict type to conflict resolution handler
PR-URL: https://github.com/nodejs/node/pull/56352
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-12-29 17:37:54 +00:00
Edigleysson Silva (Edy) a73c41c51e sqlite: aggregate constants in a single property
PR-URL: https://github.com/nodejs/node/pull/56213
Fixes: https://github.com/nodejs/node/issues/56193
Refs: https://github.com/nodejs/node/issues/56193
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
2024-12-17 17:36:58 +00:00
Colin Ihrig e5524eaefa sqlite: add support for custom functions
This commit adds support to node:sqlite for defining custom
functions that can be invoked from SQL.

Fixes: https://github.com/nodejs/node/issues/54349
PR-URL: https://github.com/nodejs/node/pull/55985
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-12-12 16:48:12 +00:00
Alex Yang 5c2f599712 sqlite: support db.loadExtension
PR-URL: https://github.com/nodejs/node/pull/53900
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-12-11 08:50:24 -08:00
tpoisseau bc701e90f3 sqlite: add StatementSync.prototype.iterate method
PR-URL: https://github.com/nodejs/node/pull/54213
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-11-22 10:21:48 +01:00
Bart Louwers 746b17e1a5 sqlite: add support for SQLite Session Extension
PR-URL: https://github.com/nodejs/node/pull/54181
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-11-18 00:57:04 +00:00
Michaël Zasso b648d37ad7 src: use env strings to create sqlite results
PR-URL: https://github.com/nodejs/node/pull/55785
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2024-11-17 09:25:03 +00:00
Tobias Nießen bdc266269c sqlite: improve error handling using MaybeLocal
As per James' suggestion, consistently use MaybeLocal and avoid Check()
and ToLocalChecked() entirely.

Refs: https://github.com/nodejs/node/pull/54687
PR-URL: https://github.com/nodejs/node/pull/55571
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2024-11-04 12:51:19 +00:00
Tobias Nießen a465b206d7 sqlite: add readOnly option
Allow opening existing SQLite databases with SQLITE_OPEN_READONLY set.

PR-URL: https://github.com/nodejs/node/pull/55567
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2024-10-31 11:41:14 +00:00
Tobias Nießen 0668e64cea sqlite: refactor open options
Move options that are only relevant for opening the database into a
self-contained class.

PR-URL: https://github.com/nodejs/node/pull/55442
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2024-10-26 00:22:07 +00:00
Fedor Indutny 6abd5457e1 sqlite: cache column names in stmt.all()
While the statement is running, it is impossible to modify the column
names and thus it is beneficial to create the host-language (JS) keys
once per all rows and reuse them for all results.

With this change the performance of `.all()` improves by around 25%
depending on the number of columns and rows in the result.

PR-URL: https://github.com/nodejs/node/pull/55373
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
2024-10-15 13:43:09 +00:00
Tobias Nießen 09d10b50dc sqlite: disable DQS misfeature by default
Double-quoted string (DQS) literals are not allowed by the SQL standard,
which defines that text enclosed in double quotes is to be interpreted
as an identifier only and never as a string literal. Nevertheless, for
historical reasons, SQLite allows double-quoted string literals in some
cases, which leads to inconsistent behavior and subtle bugs.

This commit changes the behavior of the built-in Node.js API for SQLite
such that the DQS misfeature is disabled by default. This is recommended
by the developers of SQLite. Users can explicitly enable DQS for
compatibility with legacy database schemas if necessary.

PR-URL: https://github.com/nodejs/node/pull/55297
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com>
2024-10-08 21:49:38 +00:00
Tobias Nießen 7af434fc19 sqlite: make sourceSQL and expandedSQL string-valued properties
Change sourceSQL and expandedSQL from being methods to being
string-valued properties. These fields

- are conceptually properties (and not actions),
- are derived deterministically from the current state of the object,
- require no parameters, and
- are inexpensive to compute.

Also, following the naming conventions of ECMAScript for new features,
most function names should usually contain a verb, whereas names of
(dynamically computed) properties generally should not, so the current
names also seem more appropriate for properties than for functions.

PR-URL: https://github.com/nodejs/node/pull/54721
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-10-06 17:58:22 +00:00
Tobias Nießen a49abec6c3 sqlite: enable foreign key constraints by default
For historical reasons and to maintain compatibibility with legacy
database schemas, SQLite does not enable foreign key constraints by
default. For new applications, however, this behavior is undesirable.
Currently, any application that wishes to use foreign keys must use

    PRAGMA foreign_keys = ON;

to explicitly enable enforcement of such constraints.

This commit changes the behavior of the SQLite API built into Node.js
to enable foreign key constraints by default. This behavior can be
overridden by users to maintain compatibility with legacy database
schemas.

PR-URL: https://github.com/nodejs/node/pull/54777
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2024-10-06 15:57:23 +00:00