Commit Graph

28 Commits

Author SHA1 Message Date
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