Matteo Collina and Asroy Cristian Sitorus
5cef7673ae
sqlite: prevent database close during callbacks
...
Co-authored-by: Asroy Cristian Sitorus <asroycristiansitorus@gmail.com >
Signed-off-by: Matteo Collina <hello@matteocollina.com >
PR-URL: https://github.com/nodejs/node/pull/64743
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2026-08-04 11:05:47 +00:00
Trivikram Kamat
f00fb75051
sqlite: invalidate sessions when closing database
...
DatabaseSync::DeleteSessions() deleted native sqlite3_session handles
without clearing the pointers held by their Session wrappers. Reopening
the database allowed stale session handles to be used, crashing the
process.
Track Session wrappers and delete sessions through Session::Delete() so
the wrappers are marked closed.
Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com >
Assisted-by: codex:gpt-5.6-sol
PR-URL: https://github.com/nodejs/node/pull/64783
Fixes: https://github.com/nodejs/node/issues/64782
Reviewed-By: Aviv Keller <me@aviv.sh >
2026-08-03 19:34:01 +00:00
Mohamed Sayed
d4d35c6363
sqlite: fix crash when a session outlives its database
...
Keep the database alive while a session is open so that closing the
database before the session does not leave the session pointing at
freed memory.
Signed-off-by: Mohamed Sayed <k@3zrv.com >
PR-URL: https://github.com/nodejs/node/pull/63797
Fixes: https://github.com/nodejs/node/issues/63796
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
2026-07-26 01:43:30 +00:00
Ali Hassan
ef8f8f886c
sqlite: use OneByte for ASCII text and internalize col names
...
Use simdutf to detect ASCII text values and create them
via NewFromOneByte for compact one-byte representation.
Internalize column name strings with kInternalized so V8
shares hidden classes across row objects. Cache column
names on StatementSync for iterate(), invalidated via
SQLITE_STMTSTATUS_REPREPARE on schema changes.
Refs: https://github.com/nodejs/performance/issues/181
PR-URL: https://github.com/nodejs/node/pull/61954
Refs: https://github.com/nodejs/performance/issues/181
Reviewed-By: Robert Nagy <ronagy@icloud.com >
2026-04-11 10:37:30 +00:00
Ali Hassan
4a41a002f6
sqlite: add serialize() and deserialize()
...
Add database.serialize() and database.deserialize() methods to
DatabaseSync, wrapping the sqlite3_serialize and sqlite3_deserialize
C APIs. These allow extracting an in-memory database as a Uint8Array
and loading one back, enabling snapshots, cloning, and transfer of
databases without filesystem I/O.
Refs: https://github.com/nodejs/node/issues/62575
PR-URL: https://github.com/nodejs/node/pull/62579
Refs: https://github.com/nodejs/node/issues/62575
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
2026-04-10 20:40:01 +00:00
Guilherme Araújo
88be44db0e
sqlite: handle stmt invalidation
...
PR-URL: https://github.com/nodejs/node/pull/61877
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
2026-03-02 23:29:14 +00:00
Mert Can Altin
35d3bc8fe8
sqlite: add limits property to DatabaseSync
...
PR-URL: https://github.com/nodejs/node/pull/61298
Fixes: https://github.com/nodejs/node/issues/61268
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2026-02-27 19:00:28 +00:00
Bart Louwers
f6464c57f6
sqlite: change approach to fix segfault SQLTagStore
...
PR-URL: https://github.com/nodejs/node/pull/60462
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com >
2026-01-31 06:35:30 +00:00
Bart Louwers
f475aea034
sqlite: enable defensive mode by default
...
PR-URL: https://github.com/nodejs/node/pull/61266
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Jake Yuesong Li <jake.yuesong@gmail.com >
2026-01-20 11:10:53 +00:00
Guilherme Araújo
efa7621132
sqlite: add sqlite prepare options args
...
PR-URL: https://github.com/nodejs/node/pull/61311
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
Reviewed-By: Claudio Wunder <cwunder@gnome.org >
2026-01-19 23:27:03 +00:00
Michaël Zasso
9a6e55ab3d
src: remove unused private field in SQLTagStore
...
PR-URL: https://github.com/nodejs/node/pull/61027
Reviewed-By: René <contact.9a5d6388@renegade334.me.uk >
Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
2025-12-20 06:22:38 +00:00
René
a1f421feb6
sqlite: make SQLTagStore.prototype.size a getter
...
Drive-by: make callback `args` parameter names consistent
PR-URL: https://github.com/nodejs/node/pull/60246
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
2025-12-11 02:29:09 +00:00
Bart Louwers
fd7b33e763
sqlite: allow setting defensive flag
...
PR-URL: https://github.com/nodejs/node/pull/60217
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com >
Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com >
2025-10-27 14:01:16 +00:00
James M Snell
2869c1255b
src: correct the error handling in StatementExecutionHelper
...
Error handling logic was flawed in StatementExecutionHelper
methods.
PR-URL: https://github.com/nodejs/node/pull/60040
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
2025-10-04 12:51:20 -07:00
Guilherme Araújo
b217051d36
sqlite: create authorization api
...
PR-URL: https://github.com/nodejs/node/pull/59928
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
2025-10-01 11:40:45 +02:00
0hm☘️
97e55f8ea2
sqlite: add tagged template
...
This pr introduces the support for tagged templates
And an LRU to cache the templates. We introduced a
new object called SqlTagStore that holds the ref
to Lru. This acts as the main object that allows
us to use tagged templates.
PR-URL: https://github.com/nodejs/node/pull/58748
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com >
2025-09-17 16:54:11 +00:00
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
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
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
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
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
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
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
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
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
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
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
Michaël Zasso
7fea0108d5
sqlite: return results with null prototype
...
These objects are dictionaries, and a query can return columns with
special names like `__proto__` (which would be ignored without this
change).
Also construct the object by passing vectors of properties for better
performance and improve error handling by using `MaybeLocal`.
PR-URL: https://github.com/nodejs/node/pull/54350
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
2024-08-25 10:43:17 +00:00
cjihrig
717b4018f1
sqlite: ensure statement finalization on db close
...
This commit adds statement tracking to the DatabaseSync class.
When a database is closed manually or via garbage collection, it
will force all associated prepared statements to be finalized.
This should mitigate "zombie" connections which can introduce
test flakiness in the CI on Windows.
PR-URL: https://github.com/nodejs/node/pull/54014
Fixes: https://github.com/nodejs/node/issues/54006
Reviewed-By: Moshe Atlow <moshe@atlow.co.il >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
2024-08-12 13:48:28 +00:00
Colin Ihrig
b4e8f1b6bb
lib,src,test,doc: add node:sqlite module
...
PR-URL: https://github.com/nodejs/node/pull/53752
Fixes: https://github.com/nodejs/node/issues/53264
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com >
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br >
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io >
Reviewed-By: Paolo Insogna <paolo@cowtech.it >
Reviewed-By: Matteo Collina <matteo.collina@gmail.com >
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com >
Reviewed-By: Chemi Atlow <chemi@atlow.co.il >
2024-07-09 20:33:38 +00:00