@cqlite/node 0.3.1-rc1 → 0.3.1-rc5
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.
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
CHANGED
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/* auto-generated by NAPI-RS */
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Column metadata information.
|
|
8
|
+
*
|
|
9
|
+
* Provides information about a column in the query result set,
|
|
10
|
+
* including name, data type, and nullability.
|
|
11
|
+
*/
|
|
12
|
+
export interface ColumnInfo {
|
|
13
|
+
/** Column name. */
|
|
14
|
+
name: string
|
|
15
|
+
/** CQL data type as a string (e.g., "Text", "Integer", "List"). */
|
|
16
|
+
dataType: string
|
|
17
|
+
/** Whether the column can contain null values. */
|
|
18
|
+
nullable: boolean
|
|
19
|
+
/** Column position in the result set (0-indexed). */
|
|
20
|
+
position: number
|
|
21
|
+
/** Original table name (for joined queries). */
|
|
22
|
+
tableName?: string
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Query execution result.
|
|
26
|
+
*
|
|
27
|
+
* Contains the query results serialized as JSON values for JavaScript
|
|
28
|
+
* consumption, along with metadata about the execution.
|
|
29
|
+
*/
|
|
30
|
+
export interface QueryResult {
|
|
31
|
+
/**
|
|
32
|
+
* Result rows as JSON objects.
|
|
33
|
+
* Each row is a JSON object with column names as keys.
|
|
34
|
+
*/
|
|
35
|
+
rows: Array<any>
|
|
36
|
+
/** Number of rows returned. */
|
|
37
|
+
rowCount: number
|
|
38
|
+
/** Query execution time in milliseconds. */
|
|
39
|
+
executionTimeMs: number
|
|
40
|
+
/**
|
|
41
|
+
* Column metadata for the result set.
|
|
42
|
+
* Contains information about each column's name, type, and nullability.
|
|
43
|
+
*/
|
|
44
|
+
columns: Array<ColumnInfo>
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Database statistics.
|
|
48
|
+
*
|
|
49
|
+
* Provides information about the database state including
|
|
50
|
+
* storage and memory metrics.
|
|
51
|
+
*/
|
|
52
|
+
export interface DatabaseStats {
|
|
53
|
+
/** Total number of SSTable files. */
|
|
54
|
+
totalSstables: number
|
|
55
|
+
/** Total number of rows across all SSTables. */
|
|
56
|
+
totalRows: bigint
|
|
57
|
+
/** Memory currently used by the database in bytes. */
|
|
58
|
+
memoryUsedBytes: bigint
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Database open options.
|
|
62
|
+
*
|
|
63
|
+
* Configuration options for opening a database.
|
|
64
|
+
*/
|
|
65
|
+
export interface DatabaseOptions {
|
|
66
|
+
/**
|
|
67
|
+
* Path to a CQL schema file (.cql).
|
|
68
|
+
* If provided, the schema will be loaded and used for query execution.
|
|
69
|
+
*/
|
|
70
|
+
schema?: string
|
|
71
|
+
/**
|
|
72
|
+
* Maximum memory usage in bytes.
|
|
73
|
+
* Default: 1GB (1073741824 bytes).
|
|
74
|
+
* Controls the overall memory budget for caches and internal buffers.
|
|
75
|
+
* JavaScript numbers can safely represent up to 2^53 bytes (~9 petabytes).
|
|
76
|
+
*/
|
|
77
|
+
memoryLimit?: number
|
|
78
|
+
/**
|
|
79
|
+
* Enable or disable all caches (block, row, query).
|
|
80
|
+
* Default: true (caches enabled).
|
|
81
|
+
* Set to false to minimize memory usage at the cost of performance.
|
|
82
|
+
*/
|
|
83
|
+
cacheEnabled?: boolean
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Configuration for streaming query execution.
|
|
87
|
+
*
|
|
88
|
+
* Controls memory usage during large result set iteration.
|
|
89
|
+
* Used with `executeStreaming()` for memory-efficient processing
|
|
90
|
+
* of large result sets.
|
|
91
|
+
*
|
|
92
|
+
* ## Example
|
|
93
|
+
*
|
|
94
|
+
* ```javascript
|
|
95
|
+
* const config = { bufferSize: 512, chunkSize: 5000 };
|
|
96
|
+
* for await (const row of db.executeStreaming(query, config)) {
|
|
97
|
+
* console.log(row);
|
|
98
|
+
* }
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* ## Memory Budget
|
|
102
|
+
*
|
|
103
|
+
* Default values (~11MB peak usage):
|
|
104
|
+
* - bufferSize: 1024 rows × ~1KB = ~1MB in flight
|
|
105
|
+
* - chunkSize: 10000 rows × ~1KB = ~10MB per chunk
|
|
106
|
+
*
|
|
107
|
+
* For rows with large blobs, reduce buffer sizes proportionally.
|
|
108
|
+
*/
|
|
109
|
+
export interface StreamingConfig {
|
|
110
|
+
/**
|
|
111
|
+
* Number of rows to buffer in memory during streaming.
|
|
112
|
+
* Controls backpressure. Default: 1024.
|
|
113
|
+
*/
|
|
114
|
+
bufferSize?: number
|
|
115
|
+
/**
|
|
116
|
+
* Number of rows per fetch chunk from storage.
|
|
117
|
+
* Larger chunks improve throughput, smaller chunks reduce memory.
|
|
118
|
+
* Default: 10000.
|
|
119
|
+
*/
|
|
120
|
+
chunkSize?: number
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Statistics about a prepared statement.
|
|
124
|
+
*
|
|
125
|
+
* Contains query plan information useful for optimization
|
|
126
|
+
* and debugging query performance.
|
|
127
|
+
*/
|
|
128
|
+
export interface PreparedStatementStats {
|
|
129
|
+
/** Number of parameters in the query. */
|
|
130
|
+
parameterCount: number
|
|
131
|
+
/** Type of execution plan (TableScan, IndexScan, PointLookup). */
|
|
132
|
+
planType: string
|
|
133
|
+
/** Estimated execution cost (relative metric for comparing plans). */
|
|
134
|
+
estimatedCost: number
|
|
135
|
+
/** Estimated number of rows to be returned. */
|
|
136
|
+
estimatedRows: bigint
|
|
137
|
+
/** Whether the query is cache-friendly. */
|
|
138
|
+
cacheFriendly: boolean
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Returns the version of the cqlite-node binding.
|
|
142
|
+
*
|
|
143
|
+
* @returns The semantic version string (e.g., "0.3.0")
|
|
144
|
+
*
|
|
145
|
+
* @example
|
|
146
|
+
* ```javascript
|
|
147
|
+
* const { version } = require('@cqlite/node');
|
|
148
|
+
* console.log(`CQLite version: ${version()}`);
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function version(): string
|
|
152
|
+
/**
|
|
153
|
+
* A CQLite database handle.
|
|
154
|
+
*
|
|
155
|
+
* Use `Database.open()` to create a Database instance.
|
|
156
|
+
* Always close the database when done to release resources.
|
|
157
|
+
*
|
|
158
|
+
* ## Example
|
|
159
|
+
*
|
|
160
|
+
* ```javascript
|
|
161
|
+
* const db = await Database.open('/path/to/data', { schema: '/path/to/schema.cql' });
|
|
162
|
+
* try {
|
|
163
|
+
* const result = await db.execute('SELECT * FROM users LIMIT 10');
|
|
164
|
+
* console.log(`Got ${result.rowCount} rows`);
|
|
165
|
+
* } finally {
|
|
166
|
+
* await db.close();
|
|
167
|
+
* }
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* ## Thread Safety
|
|
171
|
+
*
|
|
172
|
+
* Database handles are thread-safe and can be shared across worker threads.
|
|
173
|
+
* The `close()` method is idempotent - calling it multiple times is safe.
|
|
174
|
+
*/
|
|
175
|
+
export declare class Database {
|
|
176
|
+
/**
|
|
177
|
+
* Opens a database at the specified data directory.
|
|
178
|
+
*
|
|
179
|
+
* @param dataDir - Path to the SSTable data directory
|
|
180
|
+
* @param options - Optional configuration (schema path, etc.)
|
|
181
|
+
* @returns Promise resolving to a Database instance
|
|
182
|
+
*
|
|
183
|
+
* @example
|
|
184
|
+
* ```javascript
|
|
185
|
+
* // Basic open
|
|
186
|
+
* const db = await Database.open('/path/to/sstables');
|
|
187
|
+
*
|
|
188
|
+
* // With schema file
|
|
189
|
+
* const db = await Database.open('/path/to/sstables', {
|
|
190
|
+
* schema: '/path/to/schema.cql'
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
static open(dataDir: string, options?: DatabaseOptions | undefined | null): Promise<Database>
|
|
195
|
+
/**
|
|
196
|
+
* Execute a CQL query and return results.
|
|
197
|
+
*
|
|
198
|
+
* Executes a query against the database and returns all matching rows.
|
|
199
|
+
* For large result sets, consider using streaming (future feature).
|
|
200
|
+
*
|
|
201
|
+
* @param query - CQL SELECT statement to execute
|
|
202
|
+
* @returns Promise resolving to QueryResult with rows and metadata
|
|
203
|
+
*
|
|
204
|
+
* @example
|
|
205
|
+
* ```javascript
|
|
206
|
+
* const result = await db.execute('SELECT * FROM users LIMIT 10');
|
|
207
|
+
* console.log(`Got ${result.rowCount} rows in ${result.executionTimeMs}ms`);
|
|
208
|
+
* for (const row of result.rows) {
|
|
209
|
+
* console.log(row.name);
|
|
210
|
+
* }
|
|
211
|
+
* ```
|
|
212
|
+
*/
|
|
213
|
+
execute(query: string): Promise<QueryResult>
|
|
214
|
+
/**
|
|
215
|
+
* Get database statistics.
|
|
216
|
+
*
|
|
217
|
+
* Returns information about storage, memory usage, and other metrics.
|
|
218
|
+
*
|
|
219
|
+
* @returns Promise resolving to DatabaseStats
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```javascript
|
|
223
|
+
* const stats = await db.getStats();
|
|
224
|
+
* console.log(`SSTables: ${stats.totalSstables}`);
|
|
225
|
+
* console.log(`Total rows: ${stats.totalRows}`);
|
|
226
|
+
* console.log(`Memory: ${stats.memoryUsedBytes} bytes`);
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
229
|
+
getStats(): Promise<DatabaseStats>
|
|
230
|
+
/**
|
|
231
|
+
* Close the database and release resources.
|
|
232
|
+
*
|
|
233
|
+
* This method is idempotent - calling it multiple times is safe.
|
|
234
|
+
* After closing, any operations on the database will throw an error.
|
|
235
|
+
*
|
|
236
|
+
* @returns Promise resolving when close is complete
|
|
237
|
+
*
|
|
238
|
+
* @example
|
|
239
|
+
* ```javascript
|
|
240
|
+
* const db = await Database.open('/path/to/data');
|
|
241
|
+
* // ... use database ...
|
|
242
|
+
* await db.close();
|
|
243
|
+
* await db.close(); // Safe to call again
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
close(): Promise<void>
|
|
247
|
+
/**
|
|
248
|
+
* Check if the database is closed.
|
|
249
|
+
*
|
|
250
|
+
* @returns True if the database has been closed, false otherwise
|
|
251
|
+
*/
|
|
252
|
+
get isClosed(): boolean
|
|
253
|
+
/**
|
|
254
|
+
* Execute a CQL query with streaming results.
|
|
255
|
+
*
|
|
256
|
+
* Returns a `StreamingResult` that yields rows one at a time for memory-efficient
|
|
257
|
+
* processing of large result sets. Use with JavaScript's `for await...of` loop.
|
|
258
|
+
*
|
|
259
|
+
* Memory stays bounded by `StreamingConfig` settings (default ~11MB peak):
|
|
260
|
+
* - `bufferSize`: 1024 rows in flight
|
|
261
|
+
* - `chunkSize`: 10,000 rows per fetch chunk
|
|
262
|
+
*
|
|
263
|
+
* @param query - CQL SELECT statement to execute
|
|
264
|
+
* @param config - Optional StreamingConfig for buffer/chunk sizes
|
|
265
|
+
* @returns StreamingResult async iterable (JS wrapper makes this sync)
|
|
266
|
+
*
|
|
267
|
+
* Note: The native Rust layer returns a Promise, but the JavaScript wrapper
|
|
268
|
+
* in error-wrapper.js converts this to a synchronous return of AsyncIterable,
|
|
269
|
+
* per M4 spec requirement (Issue #347).
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```javascript
|
|
273
|
+
* // No await on executeStreaming - returns AsyncIterable directly
|
|
274
|
+
* for await (const row of db.executeStreaming('SELECT * FROM large_table')) {
|
|
275
|
+
* console.log(row.name);
|
|
276
|
+
* }
|
|
277
|
+
*
|
|
278
|
+
* // With custom config for memory constraints
|
|
279
|
+
* const config = { bufferSize: 256, chunkSize: 2500 };
|
|
280
|
+
* for await (const row of db.executeStreaming(query, config)) {
|
|
281
|
+
* process(row);
|
|
282
|
+
* }
|
|
283
|
+
*
|
|
284
|
+
* // Early termination is safe - resources cleaned up automatically
|
|
285
|
+
* for await (const row of db.executeStreaming('SELECT * FROM huge_table')) {
|
|
286
|
+
* if (row.id === targetId) {
|
|
287
|
+
* break;
|
|
288
|
+
* }
|
|
289
|
+
* }
|
|
290
|
+
* ```
|
|
291
|
+
*/
|
|
292
|
+
executeStreaming(query: string, config?: StreamingConfig | undefined | null): Promise<StreamingResult>
|
|
293
|
+
/**
|
|
294
|
+
* Execute a CQL query and return results with native JavaScript types.
|
|
295
|
+
*
|
|
296
|
+
* This method returns native JavaScript types instead of JSON:
|
|
297
|
+
* - BigInt for bigint/counter columns (preserves 64-bit precision)
|
|
298
|
+
* - Buffer for blob columns
|
|
299
|
+
* - Date for timestamp/date columns
|
|
300
|
+
* - Set for set columns
|
|
301
|
+
* - Map for map columns
|
|
302
|
+
*
|
|
303
|
+
* @param query - CQL SELECT statement to execute
|
|
304
|
+
* @returns Promise resolving to NativeQueryResult with native typed rows
|
|
305
|
+
*
|
|
306
|
+
* @example
|
|
307
|
+
* ```javascript
|
|
308
|
+
* const result = await db.executeNative('SELECT * FROM users LIMIT 10');
|
|
309
|
+
* console.log(`Got ${result.rowCount} rows`);
|
|
310
|
+
* for (const row of result.rows) {
|
|
311
|
+
* // row.id is a BigInt if the column is bigint type
|
|
312
|
+
* // row.created_at is a Date if the column is timestamp
|
|
313
|
+
* // row.data is a Buffer if the column is blob
|
|
314
|
+
* console.log(row.name, typeof row.id);
|
|
315
|
+
* }
|
|
316
|
+
* ```
|
|
317
|
+
*/
|
|
318
|
+
executeNative(query: string): Promise<{rows: object[], rowCount: number, executionTimeMs: number, columns: ColumnInfo[]}>
|
|
319
|
+
/**
|
|
320
|
+
* Prepare a CQL query for analysis.
|
|
321
|
+
*
|
|
322
|
+
* Returns a PreparedStatement that can be inspected for query plan
|
|
323
|
+
* information and statistics.
|
|
324
|
+
*/
|
|
325
|
+
prepare(query: string): Promise<PreparedStatement>
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* A prepared CQL statement.
|
|
329
|
+
*
|
|
330
|
+
* PreparedStatement holds a pre-parsed and planned query that can be
|
|
331
|
+
* inspected for metadata and statistics. Created via Database.prepare().
|
|
332
|
+
*/
|
|
333
|
+
export declare class PreparedStatement {
|
|
334
|
+
/** The original CQL query text. */
|
|
335
|
+
get query(): string
|
|
336
|
+
/**
|
|
337
|
+
* Number of parameters in the query.
|
|
338
|
+
* Returns count of placeholder parameters (?), clamped to u32::MAX.
|
|
339
|
+
*/
|
|
340
|
+
get parameterCount(): number
|
|
341
|
+
/** Get statistics about this prepared statement. */
|
|
342
|
+
stats(): PreparedStatementStats
|
|
343
|
+
/** String representation of the prepared statement. */
|
|
344
|
+
toString(): string
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Streaming query result iterator.
|
|
348
|
+
*
|
|
349
|
+
* Yields rows one at a time via `next()` method which returns an AsyncTask.
|
|
350
|
+
* JavaScript wrapper implements `Symbol.asyncIterator` for `for await...of` support.
|
|
351
|
+
*
|
|
352
|
+
* ## Resource Cleanup
|
|
353
|
+
*
|
|
354
|
+
* Resources are cleaned up when:
|
|
355
|
+
* 1. All rows consumed (`next()` returns `done: true`)
|
|
356
|
+
* 2. Iterator dropped (early break from loop triggers `return()`)
|
|
357
|
+
* 3. `close()` called explicitly
|
|
358
|
+
* 4. Error occurs
|
|
359
|
+
*
|
|
360
|
+
* ## Example (JavaScript)
|
|
361
|
+
*
|
|
362
|
+
* ```javascript
|
|
363
|
+
* // No await on executeStreaming - it returns an AsyncIterable directly
|
|
364
|
+
* for await (const row of db.executeStreaming('SELECT * FROM large_table')) {
|
|
365
|
+
* console.log(row);
|
|
366
|
+
* }
|
|
367
|
+
* ```
|
|
368
|
+
*/
|
|
369
|
+
export declare class StreamingResult {
|
|
370
|
+
/**
|
|
371
|
+
* Get the next row from the stream.
|
|
372
|
+
*
|
|
373
|
+
* Returns an object matching JavaScript's iterator protocol:
|
|
374
|
+
* - `{ value: Row, done: false }` - More rows available
|
|
375
|
+
* - `{ value: undefined, done: true }` - Stream exhausted
|
|
376
|
+
*
|
|
377
|
+
* Errors are thrown as exceptions with structured error properties
|
|
378
|
+
* (code, category, isRecoverable).
|
|
379
|
+
*
|
|
380
|
+
* @returns Promise resolving to iterator result object
|
|
381
|
+
*/
|
|
382
|
+
next(): Promise<unknown>
|
|
383
|
+
/**
|
|
384
|
+
* Number of rows received so far.
|
|
385
|
+
*
|
|
386
|
+
* This counter increases as rows are yielded from the stream.
|
|
387
|
+
* Useful for progress tracking.
|
|
388
|
+
*
|
|
389
|
+
* @returns Number of rows received
|
|
390
|
+
*/
|
|
391
|
+
get rowsReceived(): number
|
|
392
|
+
/**
|
|
393
|
+
* Column metadata for the result set.
|
|
394
|
+
*
|
|
395
|
+
* Contains information about each column's name, type, and nullability.
|
|
396
|
+
* Available immediately after creating the streaming result.
|
|
397
|
+
*
|
|
398
|
+
* @returns Array of ColumnInfo objects
|
|
399
|
+
*/
|
|
400
|
+
get columns(): Array<ColumnInfo>
|
|
401
|
+
/**
|
|
402
|
+
* Release resources early (synchronous).
|
|
403
|
+
*
|
|
404
|
+
* Called automatically when:
|
|
405
|
+
* - All rows are consumed
|
|
406
|
+
* - JavaScript iterator's `return()` is called (e.g., `break` from loop)
|
|
407
|
+
* - Error occurs during iteration
|
|
408
|
+
*
|
|
409
|
+
* Safe to call multiple times - subsequent calls are no-ops.
|
|
410
|
+
* This method is synchronous and does not need to be awaited.
|
|
411
|
+
*/
|
|
412
|
+
close(): void
|
|
413
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cqlite/node",
|
|
3
|
-
"version": "0.3.1-
|
|
3
|
+
"version": "0.3.1-rc5",
|
|
4
4
|
"description": "Node.js bindings for CQLite - read Apache Cassandra 5.0 SSTables without cluster dependencies",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"repository": {
|
|
51
51
|
"type": "git",
|
|
52
|
-
"url": "https://github.com/pmcfadin/cqlite.git",
|
|
52
|
+
"url": "git+https://github.com/pmcfadin/cqlite.git",
|
|
53
53
|
"directory": "bindings/node"
|
|
54
54
|
},
|
|
55
55
|
"license": "MIT OR Apache-2.0",
|