@stoolap/node 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -39
- package/binding.gyp +31 -0
- package/index.d.ts +141 -128
- package/index.js +14 -584
- package/lib/database.js +367 -0
- package/lib/ffi.js +183 -0
- package/lib/parse.js +246 -0
- package/lib/statement.js +371 -0
- package/lib/transaction.js +248 -0
- package/package.json +16 -24
- package/src/stoolap.c +3322 -0
package/README.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# @stoolap/node
|
|
2
2
|
|
|
3
|
-
High-performance
|
|
3
|
+
High-performance JavaScript driver for [Stoolap](https://github.com/stoolap/stoolap), a modern embedded SQL database with MVCC, time-travel queries, and full ACID compliance.
|
|
4
4
|
|
|
5
|
-
Built with
|
|
5
|
+
Built with a native N-API C addon for minimal overhead. Works with Node.js, Bun, and Deno. Provides both async and sync APIs.
|
|
6
6
|
|
|
7
7
|
[](LICENSE)
|
|
8
|
-
[](https://nodejs.org)
|
|
9
|
+
[](https://bun.sh)
|
|
10
|
+
[](https://deno.com)
|
|
9
11
|
|
|
10
12
|
## Installation
|
|
11
13
|
|
|
@@ -13,11 +15,16 @@ Built with [NAPI-RS](https://napi.rs) for native performance. Provides both asyn
|
|
|
13
15
|
npm install @stoolap/node
|
|
14
16
|
```
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
The stoolap engine shared library is pre-built for:
|
|
17
19
|
- macOS (x64, ARM64)
|
|
18
20
|
- Linux (x64, ARM64 GNU)
|
|
19
21
|
- Windows (x64 MSVC)
|
|
20
22
|
|
|
23
|
+
A C compiler is required to build the thin N-API addon on install (compiled automatically via `node-gyp`):
|
|
24
|
+
- **macOS**: `xcode-select --install`
|
|
25
|
+
- **Linux**: `sudo apt-get install build-essential` (or equivalent)
|
|
26
|
+
- **Windows**: [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) with "Desktop development with C++"
|
|
27
|
+
|
|
21
28
|
## Quick Start
|
|
22
29
|
|
|
23
30
|
```js
|
|
@@ -59,7 +66,7 @@ const users = await db.query('SELECT * FROM users ORDER BY id');
|
|
|
59
66
|
const user = await db.queryOne('SELECT * FROM users WHERE id = $1', [1]);
|
|
60
67
|
// { id: 1, name: 'Alice', email: 'alice@example.com' }
|
|
61
68
|
|
|
62
|
-
// Query in raw columnar format (faster
|
|
69
|
+
// Query in raw columnar format (faster, no per-row object creation)
|
|
63
70
|
const raw = await db.queryRaw('SELECT id, name FROM users ORDER BY id');
|
|
64
71
|
// { columns: ['id', 'name'], rows: [[1, 'Alice'], [2, 'Bob']] }
|
|
65
72
|
|
|
@@ -85,8 +92,9 @@ const db = await Database.open('file:///absolute/path/to/db');
|
|
|
85
92
|
|
|
86
93
|
| Method | Returns | Description |
|
|
87
94
|
|--------|---------|-------------|
|
|
95
|
+
| `Database.open(path)` | `Promise<Database>` | Open a database |
|
|
88
96
|
| `execute(sql, params?)` | `Promise<RunResult>` | Execute DML statement |
|
|
89
|
-
| `exec(sql)` | `Promise<void>` | Execute
|
|
97
|
+
| `exec(sql)` | `Promise<void>` | Execute a DDL statement |
|
|
90
98
|
| `query(sql, params?)` | `Promise<Object[]>` | Query rows as objects |
|
|
91
99
|
| `queryOne(sql, params?)` | `Promise<Object \| null>` | Query single row |
|
|
92
100
|
| `queryRaw(sql, params?)` | `Promise<{columns, rows}>` | Query in columnar format |
|
|
@@ -95,18 +103,20 @@ const db = await Database.open('file:///absolute/path/to/db');
|
|
|
95
103
|
|
|
96
104
|
#### Sync Methods
|
|
97
105
|
|
|
98
|
-
Sync methods run on the main thread
|
|
106
|
+
Sync methods run on the main thread. Faster for simple operations but block the event loop.
|
|
99
107
|
|
|
100
108
|
| Method | Returns | Description |
|
|
101
109
|
|--------|---------|-------------|
|
|
110
|
+
| `Database.openSync(path)` | `Database` | Open a database |
|
|
102
111
|
| `executeSync(sql, params?)` | `RunResult` | Execute DML statement |
|
|
103
|
-
| `execSync(sql)` | `void` | Execute
|
|
112
|
+
| `execSync(sql)` | `void` | Execute a DDL statement |
|
|
104
113
|
| `querySync(sql, params?)` | `Object[]` | Query rows as objects |
|
|
105
114
|
| `queryOneSync(sql, params?)` | `Object \| null` | Query single row |
|
|
106
115
|
| `queryRawSync(sql, params?)` | `{columns, rows}` | Query in columnar format |
|
|
107
116
|
| `executeBatchSync(sql, paramsArray)` | `RunResult` | Execute with multiple param sets |
|
|
108
117
|
| `beginSync()` | `Transaction` | Begin a transaction |
|
|
109
118
|
| `prepare(sql)` | `PreparedStatement` | Create a prepared statement |
|
|
119
|
+
| `closeSync()` | `void` | Close the database |
|
|
110
120
|
|
|
111
121
|
`RunResult` is `{ changes: number }`. It can be imported as a type:
|
|
112
122
|
|
|
@@ -125,7 +135,7 @@ await db.exec('CREATE TABLE kv (key TEXT PRIMARY KEY, value TEXT)');
|
|
|
125
135
|
await db.execute('INSERT INTO kv VALUES ($1, $2)', ['hello', 'world']);
|
|
126
136
|
await db.close();
|
|
127
137
|
|
|
128
|
-
// Reopen
|
|
138
|
+
// Reopen: data is still there
|
|
129
139
|
const db2 = await Database.open('./mydata');
|
|
130
140
|
const row = await db2.queryOne('SELECT * FROM kv WHERE key = $1', ['hello']);
|
|
131
141
|
// { key: 'hello', value: 'world' }
|
|
@@ -137,10 +147,10 @@ await db2.close();
|
|
|
137
147
|
Pass configuration as query parameters in the path:
|
|
138
148
|
|
|
139
149
|
```js
|
|
140
|
-
// Maximum durability
|
|
150
|
+
// Maximum durability: fsync on every WAL write
|
|
141
151
|
const db = await Database.open('./mydata?sync=full');
|
|
142
152
|
|
|
143
|
-
// High throughput
|
|
153
|
+
// High throughput: no fsync, larger buffers
|
|
144
154
|
const db = await Database.open('./mydata?sync=none&wal_buffer_size=131072');
|
|
145
155
|
|
|
146
156
|
// Custom snapshot interval with compression
|
|
@@ -158,9 +168,9 @@ Controls the durability vs. performance trade-off:
|
|
|
158
168
|
|
|
159
169
|
| Mode | Value | Description |
|
|
160
170
|
|------|-------|-------------|
|
|
161
|
-
| `none` | `sync=none` | No fsync
|
|
162
|
-
| `normal` | `sync=normal` | Fsync on commit batches
|
|
163
|
-
| `full` | `sync=full` | Fsync on every WAL write
|
|
171
|
+
| `none` | `sync=none` | No fsync. Fastest, data may be lost on crash |
|
|
172
|
+
| `normal` | `sync=normal` | Fsync on commit batches. Good balance (default) |
|
|
173
|
+
| `full` | `sync=full` | Fsync on every WAL write. Slowest, maximum durability |
|
|
164
174
|
|
|
165
175
|
##### All Configuration Parameters
|
|
166
176
|
|
|
@@ -176,7 +186,7 @@ Controls the durability vs. performance trade-off:
|
|
|
176
186
|
| `sync_interval_ms` | `10` | Minimum ms between syncs (normal mode) |
|
|
177
187
|
| `wal_compression` | `on` | LZ4 compression for WAL entries |
|
|
178
188
|
| `snapshot_compression` | `on` | LZ4 compression for snapshots |
|
|
179
|
-
| `compression` |
|
|
189
|
+
| `compression` | | Set both `wal_compression` and `snapshot_compression` |
|
|
180
190
|
| `compression_threshold` | `64` | Minimum bytes before compressing an entry |
|
|
181
191
|
|
|
182
192
|
#### Raw Query Format
|
|
@@ -207,7 +217,7 @@ console.log(result.changes); // 3
|
|
|
207
217
|
|
|
208
218
|
### PreparedStatement
|
|
209
219
|
|
|
210
|
-
Prepared statements parse SQL once and reuse the cached execution plan on every call
|
|
220
|
+
Prepared statements parse SQL once and reuse the cached execution plan on every call. No parsing or cache lookup overhead per execution.
|
|
211
221
|
|
|
212
222
|
```js
|
|
213
223
|
const insert = db.prepare('INSERT INTO users VALUES ($1, $2, $3)');
|
|
@@ -230,8 +240,9 @@ All methods mirror `Database` but without the `sql` parameter (it's bound at pre
|
|
|
230
240
|
| `queryOne(params?)` | `queryOneSync(params?)` | Query single row |
|
|
231
241
|
| `queryRaw(params?)` | `queryRawSync(params?)` | Query in columnar format |
|
|
232
242
|
| | `executeBatchSync(paramsArray)` | Execute with multiple param sets |
|
|
243
|
+
| | `finalize()` | Release the prepared statement |
|
|
233
244
|
|
|
234
|
-
Property: `sql`
|
|
245
|
+
Property: `sql` returns the SQL text of this prepared statement.
|
|
235
246
|
|
|
236
247
|
#### Async Prepared Statement
|
|
237
248
|
|
|
@@ -368,41 +379,66 @@ try {
|
|
|
368
379
|
} catch (err) {
|
|
369
380
|
console.error(err.message);
|
|
370
381
|
}
|
|
371
|
-
|
|
372
|
-
// Prepared statement — errors at prepare time for invalid SQL
|
|
373
|
-
try {
|
|
374
|
-
db.prepare('INVALID SQL HERE');
|
|
375
|
-
} catch (err) {
|
|
376
|
-
console.error(err.message);
|
|
377
|
-
}
|
|
378
382
|
```
|
|
379
383
|
|
|
380
384
|
### Supported Types
|
|
381
385
|
|
|
382
|
-
| JavaScript | Stoolap |
|
|
383
|
-
|
|
384
|
-
| `number` (integer) | `INTEGER` |
|
|
385
|
-
| `number` (float) | `FLOAT` |
|
|
386
|
-
| `string` | `TEXT` |
|
|
387
|
-
| `boolean` | `BOOLEAN` |
|
|
388
|
-
| `null` / `undefined` | `NULL` |
|
|
389
|
-
| `BigInt` | `INTEGER` |
|
|
390
|
-
| `Date` | `TIMESTAMP` |
|
|
391
|
-
| `
|
|
392
|
-
| `
|
|
386
|
+
| JavaScript | Stoolap | Notes |
|
|
387
|
+
|-----------|---------|-------|
|
|
388
|
+
| `number` (integer) | `INTEGER` | |
|
|
389
|
+
| `number` (float) | `FLOAT` | |
|
|
390
|
+
| `string` | `TEXT` | |
|
|
391
|
+
| `boolean` | `BOOLEAN` | |
|
|
392
|
+
| `null` / `undefined` | `NULL` | |
|
|
393
|
+
| `BigInt` | `INTEGER` | |
|
|
394
|
+
| `Date` | `TIMESTAMP` | |
|
|
395
|
+
| `Float32Array` | `VECTOR(N)` | Returned as `Float32Array` |
|
|
396
|
+
| `Buffer` | `TEXT` (UTF-8) | |
|
|
397
|
+
| `Object` / `Array` | `JSON` (stringified) | |
|
|
398
|
+
|
|
399
|
+
### Vector Support
|
|
400
|
+
|
|
401
|
+
Stoolap supports native vector storage and similarity search. Vectors are returned as `Float32Array` and can be passed as `Float32Array` bind parameters.
|
|
402
|
+
|
|
403
|
+
```js
|
|
404
|
+
// Create a table with a vector column
|
|
405
|
+
await db.exec('CREATE TABLE embeddings (id INTEGER PRIMARY KEY, vec VECTOR(3))');
|
|
406
|
+
|
|
407
|
+
// Insert vectors via SQL string literals
|
|
408
|
+
await db.execute("INSERT INTO embeddings VALUES (1, '[0.1, 0.2, 0.3]')");
|
|
409
|
+
|
|
410
|
+
// Query: vectors are returned as Float32Array
|
|
411
|
+
const row = await db.queryOne('SELECT vec FROM embeddings WHERE id = 1');
|
|
412
|
+
console.log(row.vec); // Float32Array(3) [0.1, 0.2, 0.3]
|
|
413
|
+
console.log(row.vec instanceof Float32Array); // true
|
|
414
|
+
|
|
415
|
+
// k-NN search with distance functions
|
|
416
|
+
const nearest = await db.query(`
|
|
417
|
+
SELECT id, VEC_DISTANCE_L2(vec, '[0.15, 0.25, 0.35]') AS dist
|
|
418
|
+
FROM embeddings ORDER BY dist LIMIT 5
|
|
419
|
+
`);
|
|
420
|
+
|
|
421
|
+
// HNSW index for fast approximate nearest neighbor search
|
|
422
|
+
await db.exec('CREATE INDEX idx ON embeddings(vec) USING HNSW');
|
|
423
|
+
```
|
|
424
|
+
|
|
425
|
+
Available distance functions: `VEC_DISTANCE_L2`, `VEC_DISTANCE_COSINE`, `VEC_DISTANCE_IP`.
|
|
426
|
+
|
|
427
|
+
See the [Stoolap Vector Search docs](https://stoolap.io/docs/data-types/vector-search/) for full details on HNSW indexes, distance metrics, and configuration.
|
|
393
428
|
|
|
394
429
|
## Building from Source
|
|
395
430
|
|
|
396
431
|
Requires:
|
|
397
|
-
- [
|
|
398
|
-
-
|
|
399
|
-
-
|
|
432
|
+
- [Node.js](https://nodejs.org) >= 18
|
|
433
|
+
- C compiler (gcc, clang, or MSVC)
|
|
434
|
+
- [node-gyp](https://github.com/nodejs/node-gyp) and its prerequisites
|
|
435
|
+
|
|
436
|
+
The stoolap shared library (`libstoolap.dylib` / `libstoolap.so` / `stoolap.dll`) must be available, either via a platform package or built from the [Stoolap](https://github.com/stoolap/stoolap) repository.
|
|
400
437
|
|
|
401
438
|
```bash
|
|
402
439
|
git clone https://github.com/stoolap/stoolap-node.git
|
|
403
440
|
cd stoolap-node
|
|
404
441
|
npm install
|
|
405
|
-
npm run build
|
|
406
442
|
npm test
|
|
407
443
|
```
|
|
408
444
|
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "stoolap",
|
|
5
|
+
"sources": ["src/stoolap.c"],
|
|
6
|
+
"include_dirs": [],
|
|
7
|
+
"cflags": ["-std=c11", "-O2"],
|
|
8
|
+
"xcode_settings": {
|
|
9
|
+
"OTHER_CFLAGS": ["-std=c11", "-O2"],
|
|
10
|
+
"MACOSX_DEPLOYMENT_TARGET": "10.15"
|
|
11
|
+
},
|
|
12
|
+
"msvs_settings": {
|
|
13
|
+
"VCCLCompilerTool": {}
|
|
14
|
+
},
|
|
15
|
+
"conditions": [
|
|
16
|
+
[
|
|
17
|
+
"OS=='win'",
|
|
18
|
+
{
|
|
19
|
+
"libraries": []
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
[
|
|
23
|
+
"OS!='win'",
|
|
24
|
+
{
|
|
25
|
+
"libraries": ["-ldl"]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
]
|
|
31
|
+
}
|
package/index.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
/* auto-generated by NAPI-RS */
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
|
|
4
1
|
export interface RunResult {
|
|
5
|
-
changes: number
|
|
2
|
+
changes: number;
|
|
6
3
|
}
|
|
7
4
|
|
|
8
5
|
export declare class Database {
|
|
9
6
|
/**
|
|
10
|
-
* Open a database. Returns a Promise that resolves to a Database instance.
|
|
7
|
+
* Open a database asynchronously. Returns a Promise that resolves to a Database instance.
|
|
11
8
|
*
|
|
12
9
|
* Accepts:
|
|
13
10
|
* - `:memory:` or empty string for in-memory database
|
|
@@ -15,162 +12,178 @@ export declare class Database {
|
|
|
15
12
|
* - `file:///path/to/db` for file-based database
|
|
16
13
|
* - Bare path like `./mydb` for file-based database
|
|
17
14
|
*/
|
|
18
|
-
static open(path: string): Promise<Database
|
|
15
|
+
static open(path: string): Promise<Database>;
|
|
16
|
+
/**
|
|
17
|
+
* Open a database synchronously.
|
|
18
|
+
*/
|
|
19
|
+
static openSync(path: string): Database;
|
|
19
20
|
/**
|
|
20
21
|
* Execute a DDL/DML statement. Returns Promise<{ changes: number }>.
|
|
21
22
|
*
|
|
22
23
|
* @param sql - SQL statement
|
|
23
24
|
* @param params - Optional: Array for positional ($1, $2) or Object for named (:key)
|
|
24
25
|
*/
|
|
25
|
-
execute(
|
|
26
|
+
execute(
|
|
27
|
+
sql: string,
|
|
28
|
+
params?: any[] | Record<string, any>,
|
|
29
|
+
): Promise<RunResult>;
|
|
26
30
|
/**
|
|
27
|
-
* Execute
|
|
28
|
-
* Returns Promise<void>.
|
|
31
|
+
* Execute a DDL statement. Returns Promise<void>.
|
|
29
32
|
*/
|
|
30
|
-
exec(sql: string): Promise<void
|
|
33
|
+
exec(sql: string): Promise<void>;
|
|
31
34
|
/**
|
|
32
35
|
* Query rows. Returns Promise<Array<Object>>.
|
|
33
36
|
*
|
|
34
37
|
* Each row is an object with column names as keys.
|
|
35
38
|
*/
|
|
36
|
-
query(
|
|
39
|
+
query(
|
|
40
|
+
sql: string,
|
|
41
|
+
params?: any[] | Record<string, any>,
|
|
42
|
+
): Promise<Record<string, any>[]>;
|
|
37
43
|
/** Query a single row. Returns Promise<Object | null>. */
|
|
38
|
-
queryOne(
|
|
44
|
+
queryOne(
|
|
45
|
+
sql: string,
|
|
46
|
+
params?: any[] | Record<string, any>,
|
|
47
|
+
): Promise<Record<string, any> | null>;
|
|
39
48
|
/**
|
|
40
49
|
* Query rows in raw format. Returns Promise<{ columns: string[], rows: any[][] }>.
|
|
41
50
|
*
|
|
42
|
-
* Faster than query()
|
|
51
|
+
* Faster than query(). Skips per-row object creation.
|
|
43
52
|
*/
|
|
44
|
-
queryRaw(
|
|
53
|
+
queryRaw(
|
|
54
|
+
sql: string,
|
|
55
|
+
params?: any[] | Record<string, any>,
|
|
56
|
+
): Promise<{ columns: string[]; rows: any[][] }>;
|
|
45
57
|
/**
|
|
46
58
|
* Execute a DML statement synchronously. Returns { changes: number }.
|
|
47
59
|
*
|
|
48
|
-
* Faster than execute() for simple operations
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
60
|
+
* Faster than execute() for simple operations. No async overhead.
|
|
61
|
+
*/
|
|
62
|
+
executeSync(sql: string, params?: any[] | Record<string, any>): RunResult;
|
|
63
|
+
/** Execute a DDL statement synchronously. */
|
|
64
|
+
execSync(sql: string): void;
|
|
65
|
+
/** Query rows synchronously. Returns Array<Object>. */
|
|
66
|
+
querySync(
|
|
67
|
+
sql: string,
|
|
68
|
+
params?: any[] | Record<string, any>,
|
|
69
|
+
): Record<string, any>[];
|
|
70
|
+
/** Query a single row synchronously. Returns Object | null. */
|
|
71
|
+
queryOneSync(
|
|
72
|
+
sql: string,
|
|
73
|
+
params?: any[] | Record<string, any>,
|
|
74
|
+
): Record<string, any> | null;
|
|
75
|
+
/** Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }. */
|
|
76
|
+
queryRawSync(
|
|
77
|
+
sql: string,
|
|
78
|
+
params?: any[] | Record<string, any>,
|
|
79
|
+
): { columns: string[]; rows: any[][] };
|
|
80
|
+
/**
|
|
81
|
+
* Execute the same SQL with multiple param sets in a single call.
|
|
82
|
+
* Auto-wraps in a transaction: begin, execute all, commit.
|
|
83
|
+
* Returns { changes: total_rows_affected }.
|
|
84
|
+
*/
|
|
85
|
+
executeBatchSync(sql: string, paramsArray: any[][]): RunResult;
|
|
86
|
+
/** Create a prepared statement (synchronous). */
|
|
87
|
+
prepare(sql: string): PreparedStatement;
|
|
88
|
+
/** Begin a transaction. Returns Promise<Transaction>. */
|
|
89
|
+
begin(): Promise<Transaction>;
|
|
90
|
+
/** Begin a transaction synchronously. Returns Transaction. */
|
|
91
|
+
beginSync(): Transaction;
|
|
92
|
+
/** Close the database. Returns Promise<void>. */
|
|
93
|
+
close(): Promise<void>;
|
|
94
|
+
/** Close the database synchronously. */
|
|
95
|
+
closeSync(): void;
|
|
83
96
|
}
|
|
84
|
-
export type JsDatabase = Database
|
|
97
|
+
export type JsDatabase = Database;
|
|
85
98
|
|
|
86
99
|
export declare class PreparedStatement {
|
|
87
100
|
/** Execute the statement (DML). Returns Promise<{ changes: number }>. */
|
|
88
|
-
execute(params?: any[] | Record<string, any>): Promise<RunResult
|
|
101
|
+
execute(params?: any[] | Record<string, any>): Promise<RunResult>;
|
|
89
102
|
/** Query rows. Returns Promise<Array<Object>>. */
|
|
90
|
-
query(params?: any[] | Record<string, any>): Promise<Record<string, any>[]
|
|
103
|
+
query(params?: any[] | Record<string, any>): Promise<Record<string, any>[]>;
|
|
91
104
|
/** Query single row. Returns Promise<Object | null>. */
|
|
92
|
-
queryOne(
|
|
105
|
+
queryOne(
|
|
106
|
+
params?: any[] | Record<string, any>,
|
|
107
|
+
): Promise<Record<string, any> | null>;
|
|
93
108
|
/** Query rows in raw format. Returns Promise<{ columns: string[], rows: any[][] }>. */
|
|
94
|
-
queryRaw(
|
|
109
|
+
queryRaw(
|
|
110
|
+
params?: any[] | Record<string, any>,
|
|
111
|
+
): Promise<{ columns: string[]; rows: any[][] }>;
|
|
95
112
|
/** Execute synchronously. Returns { changes: number }. */
|
|
96
|
-
executeSync(params?: any[] | Record<string, any>): RunResult
|
|
97
|
-
/**
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
executeBatchSync(paramsArray: any[][]): RunResult
|
|
118
|
-
/** Get the SQL text of this prepared statement. */
|
|
119
|
-
get sql(): string
|
|
113
|
+
executeSync(params?: any[] | Record<string, any>): RunResult;
|
|
114
|
+
/** Query rows synchronously. Returns Array<Object>. */
|
|
115
|
+
querySync(params?: any[] | Record<string, any>): Record<string, any>[];
|
|
116
|
+
/** Query single row synchronously. Returns Object | null. */
|
|
117
|
+
queryOneSync(
|
|
118
|
+
params?: any[] | Record<string, any>,
|
|
119
|
+
): Record<string, any> | null;
|
|
120
|
+
/** Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }. */
|
|
121
|
+
queryRawSync(params?: any[] | Record<string, any>): {
|
|
122
|
+
columns: string[];
|
|
123
|
+
rows: any[][];
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Execute the prepared SQL with multiple param sets in a single call.
|
|
127
|
+
* Returns { changes: total_rows_affected }.
|
|
128
|
+
*/
|
|
129
|
+
executeBatchSync(paramsArray: any[][]): RunResult;
|
|
130
|
+
/** Get the SQL text of this prepared statement. */
|
|
131
|
+
get sql(): string;
|
|
132
|
+
/** Release the prepared statement. */
|
|
133
|
+
finalize(): void;
|
|
120
134
|
}
|
|
121
|
-
export type JsPreparedStatement = PreparedStatement
|
|
135
|
+
export type JsPreparedStatement = PreparedStatement;
|
|
122
136
|
|
|
123
137
|
export declare class Transaction {
|
|
124
|
-
/**
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
/** Execute a DML statement within the transaction. Returns Promise<{ changes: number }>. */
|
|
139
|
+
execute(
|
|
140
|
+
sql: string,
|
|
141
|
+
params?: any[] | Record<string, any>,
|
|
142
|
+
): Promise<RunResult>;
|
|
143
|
+
/** Query rows within the transaction. Returns Promise<Array<Object>>. */
|
|
144
|
+
query(
|
|
145
|
+
sql: string,
|
|
146
|
+
params?: any[] | Record<string, any>,
|
|
147
|
+
): Promise<Record<string, any>[]>;
|
|
148
|
+
/** Query a single row within the transaction. Returns Promise<Object | null>. */
|
|
149
|
+
queryOne(
|
|
150
|
+
sql: string,
|
|
151
|
+
params?: any[] | Record<string, any>,
|
|
152
|
+
): Promise<Record<string, any> | null>;
|
|
153
|
+
/** Query rows in raw format within the transaction. Returns Promise<{ columns: string[], rows: any[][] }>. */
|
|
154
|
+
queryRaw(
|
|
155
|
+
sql: string,
|
|
156
|
+
params?: any[] | Record<string, any>,
|
|
157
|
+
): Promise<{ columns: string[]; rows: any[][] }>;
|
|
144
158
|
/** Commit the transaction. Returns Promise<void>. */
|
|
145
|
-
commit(): Promise<void
|
|
159
|
+
commit(): Promise<void>;
|
|
146
160
|
/** Rollback the transaction. Returns Promise<void>. */
|
|
147
|
-
rollback(): Promise<void
|
|
161
|
+
rollback(): Promise<void>;
|
|
148
162
|
/** Execute a DML statement synchronously. Returns { changes: number }. */
|
|
149
|
-
executeSync(sql: string, params?: any[] | Record<string, any>): RunResult
|
|
150
|
-
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
/** Commit the transaction synchronously. */
|
|
166
|
-
commitSync(): void
|
|
167
|
-
/**
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
rollbackSync(): void
|
|
163
|
+
executeSync(sql: string, params?: any[] | Record<string, any>): RunResult;
|
|
164
|
+
/** Query rows synchronously. Returns Array<Object>. */
|
|
165
|
+
querySync(
|
|
166
|
+
sql: string,
|
|
167
|
+
params?: any[] | Record<string, any>,
|
|
168
|
+
): Record<string, any>[];
|
|
169
|
+
/** Query a single row synchronously. Returns Object | null. */
|
|
170
|
+
queryOneSync(
|
|
171
|
+
sql: string,
|
|
172
|
+
params?: any[] | Record<string, any>,
|
|
173
|
+
): Record<string, any> | null;
|
|
174
|
+
/** Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }. */
|
|
175
|
+
queryRawSync(
|
|
176
|
+
sql: string,
|
|
177
|
+
params?: any[] | Record<string, any>,
|
|
178
|
+
): { columns: string[]; rows: any[][] };
|
|
179
|
+
/** Commit the transaction synchronously. */
|
|
180
|
+
commitSync(): void;
|
|
181
|
+
/**
|
|
182
|
+
* Execute the same SQL with multiple param sets in a single call.
|
|
183
|
+
* Returns { changes: total_rows_affected }.
|
|
184
|
+
*/
|
|
185
|
+
executeBatchSync(sql: string, paramsArray: any[][]): RunResult;
|
|
186
|
+
/** Rollback the transaction synchronously. */
|
|
187
|
+
rollbackSync(): void;
|
|
175
188
|
}
|
|
176
|
-
export type JsTransaction = Transaction
|
|
189
|
+
export type JsTransaction = Transaction;
|