@stoolap/node 0.3.3 → 0.3.4

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 CHANGED
@@ -1,11 +1,11 @@
1
1
  # @stoolap/node
2
2
 
3
- High-performance Node.js driver for [Stoolap](https://github.com/stoolap/stoolap) — a modern embedded SQL database with MVCC, time-travel queries, and full ACID compliance.
3
+ High-performance Node.js 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 [NAPI-RS](https://napi.rs) for native performance. Provides both async and sync APIs with direct V8 object creation for minimal overhead.
5
+ Built with a native N-API C addon for minimal overhead. Provides both async and sync APIs.
6
6
 
7
7
  [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
8
- [![Node](https://img.shields.io/badge/node-%3E%3D22-brightgreen.svg)](https://nodejs.org)
8
+ [![Node](https://img.shields.io/badge/node-%3E%3D18-brightgreen.svg)](https://nodejs.org)
9
9
 
10
10
  ## Installation
11
11
 
@@ -13,11 +13,16 @@ Built with [NAPI-RS](https://napi.rs) for native performance. Provides both asyn
13
13
  npm install @stoolap/node
14
14
  ```
15
15
 
16
- Pre-built binaries are available for:
16
+ The stoolap engine shared library is pre-built for:
17
17
  - macOS (x64, ARM64)
18
18
  - Linux (x64, ARM64 GNU)
19
19
  - Windows (x64 MSVC)
20
20
 
21
+ A C compiler is required to build the thin N-API addon on install (compiled automatically via `node-gyp`):
22
+ - **macOS**: `xcode-select --install`
23
+ - **Linux**: `sudo apt-get install build-essential` (or equivalent)
24
+ - **Windows**: [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/) with "Desktop development with C++"
25
+
21
26
  ## Quick Start
22
27
 
23
28
  ```js
@@ -59,7 +64,7 @@ const users = await db.query('SELECT * FROM users ORDER BY id');
59
64
  const user = await db.queryOne('SELECT * FROM users WHERE id = $1', [1]);
60
65
  // { id: 1, name: 'Alice', email: 'alice@example.com' }
61
66
 
62
- // Query in raw columnar format (faster — no per-row object creation)
67
+ // Query in raw columnar format (faster, no per-row object creation)
63
68
  const raw = await db.queryRaw('SELECT id, name FROM users ORDER BY id');
64
69
  // { columns: ['id', 'name'], rows: [[1, 'Alice'], [2, 'Bob']] }
65
70
 
@@ -85,8 +90,9 @@ const db = await Database.open('file:///absolute/path/to/db');
85
90
 
86
91
  | Method | Returns | Description |
87
92
  |--------|---------|-------------|
93
+ | `Database.open(path)` | `Promise<Database>` | Open a database |
88
94
  | `execute(sql, params?)` | `Promise<RunResult>` | Execute DML statement |
89
- | `exec(sql)` | `Promise<void>` | Execute one or more statements |
95
+ | `exec(sql)` | `Promise<void>` | Execute a DDL statement |
90
96
  | `query(sql, params?)` | `Promise<Object[]>` | Query rows as objects |
91
97
  | `queryOne(sql, params?)` | `Promise<Object \| null>` | Query single row |
92
98
  | `queryRaw(sql, params?)` | `Promise<{columns, rows}>` | Query in columnar format |
@@ -95,18 +101,20 @@ const db = await Database.open('file:///absolute/path/to/db');
95
101
 
96
102
  #### Sync Methods
97
103
 
98
- Sync methods run on the main thread — faster for simple operations but block the event loop.
104
+ Sync methods run on the main thread. Faster for simple operations but block the event loop.
99
105
 
100
106
  | Method | Returns | Description |
101
107
  |--------|---------|-------------|
108
+ | `Database.openSync(path)` | `Database` | Open a database |
102
109
  | `executeSync(sql, params?)` | `RunResult` | Execute DML statement |
103
- | `execSync(sql)` | `void` | Execute one or more statements |
110
+ | `execSync(sql)` | `void` | Execute a DDL statement |
104
111
  | `querySync(sql, params?)` | `Object[]` | Query rows as objects |
105
112
  | `queryOneSync(sql, params?)` | `Object \| null` | Query single row |
106
113
  | `queryRawSync(sql, params?)` | `{columns, rows}` | Query in columnar format |
107
114
  | `executeBatchSync(sql, paramsArray)` | `RunResult` | Execute with multiple param sets |
108
115
  | `beginSync()` | `Transaction` | Begin a transaction |
109
116
  | `prepare(sql)` | `PreparedStatement` | Create a prepared statement |
117
+ | `closeSync()` | `void` | Close the database |
110
118
 
111
119
  `RunResult` is `{ changes: number }`. It can be imported as a type:
112
120
 
@@ -125,7 +133,7 @@ await db.exec('CREATE TABLE kv (key TEXT PRIMARY KEY, value TEXT)');
125
133
  await db.execute('INSERT INTO kv VALUES ($1, $2)', ['hello', 'world']);
126
134
  await db.close();
127
135
 
128
- // Reopen — data is still there
136
+ // Reopen: data is still there
129
137
  const db2 = await Database.open('./mydata');
130
138
  const row = await db2.queryOne('SELECT * FROM kv WHERE key = $1', ['hello']);
131
139
  // { key: 'hello', value: 'world' }
@@ -137,10 +145,10 @@ await db2.close();
137
145
  Pass configuration as query parameters in the path:
138
146
 
139
147
  ```js
140
- // Maximum durability — fsync on every WAL write
148
+ // Maximum durability: fsync on every WAL write
141
149
  const db = await Database.open('./mydata?sync=full');
142
150
 
143
- // High throughput — no fsync, larger buffers
151
+ // High throughput: no fsync, larger buffers
144
152
  const db = await Database.open('./mydata?sync=none&wal_buffer_size=131072');
145
153
 
146
154
  // Custom snapshot interval with compression
@@ -158,9 +166,9 @@ Controls the durability vs. performance trade-off:
158
166
 
159
167
  | Mode | Value | Description |
160
168
  |------|-------|-------------|
161
- | `none` | `sync=none` | No fsync — fastest, data may be lost on crash |
162
- | `normal` | `sync=normal` | Fsync on commit batches — good balance (default) |
163
- | `full` | `sync=full` | Fsync on every WAL write — slowest, maximum durability |
169
+ | `none` | `sync=none` | No fsync. Fastest, data may be lost on crash |
170
+ | `normal` | `sync=normal` | Fsync on commit batches. Good balance (default) |
171
+ | `full` | `sync=full` | Fsync on every WAL write. Slowest, maximum durability |
164
172
 
165
173
  ##### All Configuration Parameters
166
174
 
@@ -176,7 +184,7 @@ Controls the durability vs. performance trade-off:
176
184
  | `sync_interval_ms` | `10` | Minimum ms between syncs (normal mode) |
177
185
  | `wal_compression` | `on` | LZ4 compression for WAL entries |
178
186
  | `snapshot_compression` | `on` | LZ4 compression for snapshots |
179
- | `compression` | — | Set both `wal_compression` and `snapshot_compression` |
187
+ | `compression` | | Set both `wal_compression` and `snapshot_compression` |
180
188
  | `compression_threshold` | `64` | Minimum bytes before compressing an entry |
181
189
 
182
190
  #### Raw Query Format
@@ -207,7 +215,7 @@ console.log(result.changes); // 3
207
215
 
208
216
  ### PreparedStatement
209
217
 
210
- Prepared statements parse SQL once and reuse the cached execution plan on every call — no parsing or cache lookup overhead per execution.
218
+ Prepared statements parse SQL once and reuse the cached execution plan on every call. No parsing or cache lookup overhead per execution.
211
219
 
212
220
  ```js
213
221
  const insert = db.prepare('INSERT INTO users VALUES ($1, $2, $3)');
@@ -230,8 +238,9 @@ All methods mirror `Database` but without the `sql` parameter (it's bound at pre
230
238
  | `queryOne(params?)` | `queryOneSync(params?)` | Query single row |
231
239
  | `queryRaw(params?)` | `queryRawSync(params?)` | Query in columnar format |
232
240
  | | `executeBatchSync(paramsArray)` | Execute with multiple param sets |
241
+ | | `finalize()` | Release the prepared statement |
233
242
 
234
- Property: `sql` — returns the SQL text of this prepared statement.
243
+ Property: `sql` returns the SQL text of this prepared statement.
235
244
 
236
245
  #### Async Prepared Statement
237
246
 
@@ -368,41 +377,66 @@ try {
368
377
  } catch (err) {
369
378
  console.error(err.message);
370
379
  }
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
380
  ```
379
381
 
380
382
  ### Supported Types
381
383
 
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
- | `Buffer` | `TEXT` (UTF-8) |
392
- | `Object` / `Array` | `JSON` (stringified) |
384
+ | JavaScript | Stoolap | Notes |
385
+ |-----------|---------|-------|
386
+ | `number` (integer) | `INTEGER` | |
387
+ | `number` (float) | `FLOAT` | |
388
+ | `string` | `TEXT` | |
389
+ | `boolean` | `BOOLEAN` | |
390
+ | `null` / `undefined` | `NULL` | |
391
+ | `BigInt` | `INTEGER` | |
392
+ | `Date` | `TIMESTAMP` | |
393
+ | `Float32Array` | `VECTOR(N)` | Returned as `Float32Array` |
394
+ | `Buffer` | `TEXT` (UTF-8) | |
395
+ | `Object` / `Array` | `JSON` (stringified) | |
396
+
397
+ ### Vector Support
398
+
399
+ Stoolap supports native vector storage and similarity search. Vectors are returned as `Float32Array` and can be passed as `Float32Array` bind parameters.
400
+
401
+ ```js
402
+ // Create a table with a vector column
403
+ await db.exec('CREATE TABLE embeddings (id INTEGER PRIMARY KEY, vec VECTOR(3))');
404
+
405
+ // Insert vectors via SQL string literals
406
+ await db.execute("INSERT INTO embeddings VALUES (1, '[0.1, 0.2, 0.3]')");
407
+
408
+ // Query: vectors are returned as Float32Array
409
+ const row = await db.queryOne('SELECT vec FROM embeddings WHERE id = 1');
410
+ console.log(row.vec); // Float32Array(3) [0.1, 0.2, 0.3]
411
+ console.log(row.vec instanceof Float32Array); // true
412
+
413
+ // k-NN search with distance functions
414
+ const nearest = await db.query(`
415
+ SELECT id, VEC_DISTANCE_L2(vec, '[0.15, 0.25, 0.35]') AS dist
416
+ FROM embeddings ORDER BY dist LIMIT 5
417
+ `);
418
+
419
+ // HNSW index for fast approximate nearest neighbor search
420
+ await db.exec('CREATE INDEX idx ON embeddings(vec) USING HNSW');
421
+ ```
422
+
423
+ Available distance functions: `VEC_DISTANCE_L2`, `VEC_DISTANCE_COSINE`, `VEC_DISTANCE_IP`.
424
+
425
+ 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
426
 
394
427
  ## Building from Source
395
428
 
396
429
  Requires:
397
- - [Rust](https://rustup.rs) (stable)
398
- - [Node.js](https://nodejs.org) >= 22 (with development headers)
399
- - C++ compiler (for V8 helpers)
430
+ - [Node.js](https://nodejs.org) >= 18
431
+ - C compiler (gcc, clang, or MSVC)
432
+ - [node-gyp](https://github.com/nodejs/node-gyp) and its prerequisites
433
+
434
+ 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
435
 
401
436
  ```bash
402
437
  git clone https://github.com/stoolap/stoolap-node.git
403
438
  cd stoolap-node
404
439
  npm install
405
- npm run build
406
440
  npm test
407
441
  ```
408
442
 
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(sql: string, params?: any[] | Record<string, any>): Promise<RunResult>
26
+ execute(
27
+ sql: string,
28
+ params?: any[] | Record<string, any>,
29
+ ): Promise<RunResult>;
26
30
  /**
27
- * Execute one or more SQL statements separated by semicolons.
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(sql: string, params?: any[] | Record<string, any>): Promise<Record<string, any>[]>
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(sql: string, params?: any[] | Record<string, any>): Promise<Record<string, any> | null>
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() — skips per-row object creation.
51
+ * Faster than query(). Skips per-row object creation.
43
52
  */
44
- queryRaw(sql: string, params?: any[] | Record<string, any>): Promise<{ columns: string[], rows: any[][] }>
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 — no async overhead.
49
- * Blocks the event loop, so use for fast operations only.
50
- */
51
- executeSync(sql: string, params?: any[] | Record<string, any>): RunResult
52
- /**
53
- * Query rows synchronously. Returns Array<Object>.
54
- * Uses direct V8 bulk object creation — bypasses NAPI per-property overhead.
55
- */
56
- querySync(sql: string, params?: any[] | Record<string, any>): Record<string, any>[]
57
- /**
58
- * Query a single row synchronously. Returns Object | null.
59
- * Uses direct V8 bulk object creation — optimal hidden class in one call.
60
- */
61
- queryOneSync(sql: string, params?: any[] | Record<string, any>): Record<string, any> | null
62
- /**
63
- * Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }.
64
- * Uses direct V8 bulk array creation — bypasses NAPI per-element overhead.
65
- */
66
- queryRawSync(sql: string, params?: any[] | Record<string, any>): { columns: string[], rows: any[][] }
67
- /**
68
- * Execute the same SQL with multiple param sets in a single call.
69
- * Parses SQL once, auto-wraps in a transaction: begin, execute all, commit.
70
- * Returns { changes: total_rows_affected }.
71
- */
72
- executeBatchSync(sql: string, paramsArray: any[][]): RunResult
73
- /** Execute one or more SQL statements synchronously. */
74
- execSync(sql: string): void
75
- /** Create a prepared statement (synchronous — parses and caches the plan). */
76
- prepare(sql: string): JsPreparedStatement
77
- /** Begin a transaction. Returns Promise<Transaction>. */
78
- begin(): Promise<Transaction>
79
- /** Begin a transaction synchronously. Returns Transaction. */
80
- beginSync(): Transaction
81
- /** Close the database. Returns Promise<void>. */
82
- close(): Promise<void>
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(params?: any[] | Record<string, any>): Promise<Record<string, any> | null>
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(params?: any[] | Record<string, any>): Promise<{ columns: string[], rows: any[][] }>
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
- * Query rows synchronously. Returns Array<Object>.
99
- * Uses direct V8 bulk object creation — bypasses NAPI per-property overhead.
100
- */
101
- querySync(params?: any[] | Record<string, any>): Record<string, any>[]
102
- /**
103
- * Query single row synchronously. Returns Object | null.
104
- * Uses direct V8 bulk object creation — optimal hidden class in one call.
105
- */
106
- queryOneSync(params?: any[] | Record<string, any>): Record<string, any> | null
107
- /**
108
- * Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }.
109
- * Uses direct V8 bulk array creation — bypasses NAPI per-element overhead.
110
- */
111
- queryRawSync(params?: any[] | Record<string, any>): { columns: string[], rows: any[][] }
112
- /**
113
- * Execute the prepared SQL with multiple param sets in a single call.
114
- * Uses pre-cached AST, auto-wraps in a transaction: begin, execute all, commit.
115
- * Returns { changes: total_rows_affected }.
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
- * Execute a DML statement within the transaction.
126
- * Returns Promise<{ changes: number }>.
127
- */
128
- execute(sql: string, params?: any[] | Record<string, any>): Promise<RunResult>
129
- /**
130
- * Query rows within the transaction.
131
- * Returns Promise<Array<Object>>.
132
- */
133
- query(sql: string, params?: any[] | Record<string, any>): Promise<Record<string, any>[]>
134
- /**
135
- * Query a single row within the transaction.
136
- * Returns Promise<Object | null>.
137
- */
138
- queryOne(sql: string, params?: any[] | Record<string, any>): Promise<Record<string, any> | null>
139
- /**
140
- * Query rows in raw format within the transaction.
141
- * Returns Promise<{ columns: string[], rows: any[][] }>.
142
- */
143
- queryRaw(sql: string, params?: any[] | Record<string, any>): Promise<{ columns: string[], rows: any[][] }>
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
- * Query rows synchronously. Returns Array<Object>.
152
- * Uses direct V8 bulk object creation — bypasses NAPI per-property overhead.
153
- */
154
- querySync(sql: string, params?: any[] | Record<string, any>): Record<string, any>[]
155
- /**
156
- * Query a single row synchronously. Returns Object | null.
157
- * Uses direct V8 bulk object creation — optimal hidden class in one call.
158
- */
159
- queryOneSync(sql: string, params?: any[] | Record<string, any>): Record<string, any> | null
160
- /**
161
- * Query rows in raw format synchronously. Returns { columns: string[], rows: any[][] }.
162
- * Uses direct V8 bulk array creation — bypasses NAPI per-element overhead.
163
- */
164
- queryRawSync(sql: string, params?: any[] | Record<string, any>): { columns: string[], rows: any[][] }
165
- /** Commit the transaction synchronously. */
166
- commitSync(): void
167
- /**
168
- * Execute the same SQL with multiple param sets in a single call.
169
- * Parses SQL once, locks the transaction once — eliminates per-call overhead.
170
- * Returns { changes: total_rows_affected }.
171
- */
172
- executeBatchSync(sql: string, paramsArray: any[][]): RunResult
173
- /** Rollback the transaction synchronously. */
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;