@ladybugdb/core-darwin-arm64 0.17.0-dev.20260528 → 0.17.0

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/connection.js CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  const LbugNative = require("./lbug_native.js");
4
4
  const QueryResult = require("./query_result.js");
5
+ const { ArrowQueryResult } = require("./query_result.js");
5
6
  const PreparedStatement = require("./prepared_statement.js");
6
7
 
7
8
  class Connection {
@@ -320,6 +321,162 @@ class Connection {
320
321
  return this._unwrapMultipleQueryResultsSync(nodeQueryResult);
321
322
  }
322
323
 
324
+ /**
325
+ * Execute a query with the native Arrow result collector.
326
+ * @param {String} statement the statement to execute.
327
+ * @param {Number} chunkSize native Arrow chunk size.
328
+ * @returns {Promise<lbug.ArrowQueryResult>} a promise that resolves to the Arrow query result.
329
+ */
330
+ queryArrow(statement, chunkSize = 1000) {
331
+ return new Promise((resolve, reject) => {
332
+ if (typeof statement !== "string") {
333
+ return reject(new Error("statement must be a string."));
334
+ }
335
+ if (typeof chunkSize !== "number" || chunkSize <= 0) {
336
+ return reject(new Error("chunkSize must be a positive number."));
337
+ }
338
+ this._getConnection()
339
+ .then((connection) => {
340
+ const nodeQueryResult = new LbugNative.NodeQueryResult();
341
+ try {
342
+ connection.queryArrowAsync(statement, chunkSize, nodeQueryResult, (err) => {
343
+ if (err) {
344
+ return reject(err);
345
+ }
346
+ return resolve(new ArrowQueryResult(this, nodeQueryResult, chunkSize));
347
+ });
348
+ } catch (e) {
349
+ return reject(e);
350
+ }
351
+ })
352
+ .catch((err) => {
353
+ return reject(err);
354
+ });
355
+ });
356
+ }
357
+
358
+ /**
359
+ * Execute a query synchronously with the native Arrow result collector.
360
+ * @param {String} statement the statement to execute.
361
+ * @param {Number} chunkSize native Arrow chunk size.
362
+ * @returns {lbug.ArrowQueryResult} the Arrow query result.
363
+ */
364
+ queryArrowSync(statement, chunkSize = 1000) {
365
+ if (typeof statement !== "string") {
366
+ throw new Error("statement must be a string.");
367
+ }
368
+ if (typeof chunkSize !== "number" || chunkSize <= 0) {
369
+ throw new Error("chunkSize must be a positive number.");
370
+ }
371
+ const connection = this._getConnectionSync();
372
+ const nodeQueryResult = new LbugNative.NodeQueryResult();
373
+ connection.queryArrowSync(statement, chunkSize, nodeQueryResult);
374
+ return new ArrowQueryResult(this, nodeQueryResult, chunkSize);
375
+ }
376
+
377
+ /**
378
+ * Create an Arrow memory-backed node table from Arrow C Data Interface pointers.
379
+ * Ownership of the schema and arrays is transferred to Ladybug.
380
+ * @param {String} tableName the node table name to create.
381
+ * @param {BigInt|External} schemaPtr pointer to an ArrowSchema.
382
+ * @param {BigInt|External|Array<BigInt|External>} arraysPtr pointer to contiguous ArrowArray objects, or an array of ArrowArray pointers.
383
+ * @param {Number} numArrays number of ArrowArray batches when arraysPtr is contiguous.
384
+ * @returns {lbug.QueryResult} the table creation query result.
385
+ */
386
+ createArrowTableSync(tableName, schemaPtr, arraysPtr, numArrays = 1) {
387
+ if (typeof tableName !== "string") {
388
+ throw new Error("tableName must be a string.");
389
+ }
390
+ if (!Array.isArray(arraysPtr) && (typeof numArrays !== "number" || numArrays <= 0)) {
391
+ throw new Error("numArrays must be a positive number.");
392
+ }
393
+ const connection = this._getConnectionSync();
394
+ const nodeQueryResult = new LbugNative.NodeQueryResult();
395
+ connection.createArrowTableSync(tableName, schemaPtr, arraysPtr, numArrays, nodeQueryResult);
396
+ return new QueryResult(this, nodeQueryResult);
397
+ }
398
+
399
+ /**
400
+ * Create an Arrow memory-backed relationship table from Arrow C Data Interface pointers.
401
+ * For flat layout (default): the Arrow table must contain endpoint columns named "from" and "to".
402
+ * For CSR layout: pass indptrSchemaPtr and indptrArraysPtr; dstColName names the destination column.
403
+ * Ownership of the schema and arrays is transferred to Ladybug.
404
+ */
405
+ createArrowRelTableSync(
406
+ tableName,
407
+ srcTableName,
408
+ dstTableName,
409
+ schemaPtr,
410
+ arraysPtr,
411
+ numArrays = 1,
412
+ indptrSchemaPtr = null,
413
+ indptrArraysPtr = null,
414
+ numIndptrArrays = 1,
415
+ dstColName = "to"
416
+ ) {
417
+ if (typeof tableName !== "string") {
418
+ throw new Error("tableName must be a string.");
419
+ }
420
+ if (typeof srcTableName !== "string" || typeof dstTableName !== "string") {
421
+ throw new Error("srcTableName and dstTableName must be strings.");
422
+ }
423
+ if (!Array.isArray(arraysPtr) && (typeof numArrays !== "number" || numArrays <= 0)) {
424
+ throw new Error("numArrays must be a positive number.");
425
+ }
426
+ const connection = this._getConnectionSync();
427
+ const nodeQueryResult = new LbugNative.NodeQueryResult();
428
+ if (indptrSchemaPtr != null) {
429
+ if (indptrArraysPtr == null) {
430
+ throw new Error("indptrArraysPtr must be provided in CSR mode.");
431
+ }
432
+ if (!Array.isArray(indptrArraysPtr) && (!Number.isSafeInteger(numIndptrArrays) || numIndptrArrays <= 0)) {
433
+ throw new Error("numIndptrArrays must be a positive integer.");
434
+ }
435
+ if (typeof dstColName !== "string") {
436
+ throw new Error("dstColName must be a string.");
437
+ }
438
+ connection.createArrowRelTableSync(
439
+ tableName,
440
+ srcTableName,
441
+ dstTableName,
442
+ schemaPtr,
443
+ arraysPtr,
444
+ numArrays,
445
+ indptrSchemaPtr,
446
+ indptrArraysPtr,
447
+ numIndptrArrays,
448
+ dstColName,
449
+ nodeQueryResult
450
+ );
451
+ } else {
452
+ connection.createArrowRelTableSync(
453
+ tableName,
454
+ srcTableName,
455
+ dstTableName,
456
+ schemaPtr,
457
+ arraysPtr,
458
+ numArrays,
459
+ nodeQueryResult
460
+ );
461
+ }
462
+ return new QueryResult(this, nodeQueryResult);
463
+ }
464
+
465
+ /**
466
+ * Drop an Arrow memory-backed table and unregister its Arrow data.
467
+ * @param {String} tableName the Arrow table name.
468
+ * @returns {lbug.QueryResult} the drop query result.
469
+ */
470
+ dropArrowTableSync(tableName) {
471
+ if (typeof tableName !== "string") {
472
+ throw new Error("tableName must be a string.");
473
+ }
474
+ const connection = this._getConnectionSync();
475
+ const nodeQueryResult = new LbugNative.NodeQueryResult();
476
+ connection.dropArrowTableSync(tableName, nodeQueryResult);
477
+ return new QueryResult(this, nodeQueryResult);
478
+ }
479
+
323
480
  /**
324
481
  * Internal function to get the next query result for multiple query results.
325
482
  * @param {LbugNative.NodeQueryResult} nodeQueryResult the current node query result.
package/database.js CHANGED
@@ -26,6 +26,7 @@ class Database {
26
26
  * the error occured.
27
27
  * @param {Boolean} enableChecksums If true, the database will use checksums to detect corruption in the
28
28
  * WAL file.
29
+ * @param {Boolean} enableDefaultHashIndex If true, node tables create the default primary-key hash index.
29
30
  */
30
31
  constructor(
31
32
  databasePath,
@@ -37,6 +38,7 @@ class Database {
37
38
  checkpointThreshold = -1,
38
39
  throwOnWalReplayFailure = true,
39
40
  enableChecksums = true,
41
+ enableDefaultHashIndex = true,
40
42
  ) {
41
43
  if (!databasePath) {
42
44
  databasePath = ":memory:";
@@ -65,7 +67,8 @@ class Database {
65
67
  autoCheckpoint,
66
68
  checkpointThreshold,
67
69
  throwOnWalReplayFailure,
68
- enableChecksums
70
+ enableChecksums,
71
+ enableDefaultHashIndex
69
72
  );
70
73
  this._isInitialized = false;
71
74
  this._initPromise = null;
package/index.js CHANGED
@@ -4,12 +4,25 @@ const Connection = require("./connection.js");
4
4
  const Database = require("./database.js");
5
5
  const PreparedStatement = require("./prepared_statement.js");
6
6
  const QueryResult = require("./query_result.js");
7
+ const { ArrowQueryResult } = require("./query_result.js");
8
+
9
+ function json(value) {
10
+ const stringValue = typeof value === "string" ? value : JSON.stringify(value);
11
+ return Object.freeze(
12
+ Object.defineProperties({}, {
13
+ _lbugType: { value: "JSON", enumerable: false },
14
+ value: { value: stringValue, enumerable: false },
15
+ })
16
+ );
17
+ }
7
18
 
8
19
  module.exports = {
9
20
  Connection,
10
21
  Database,
11
22
  PreparedStatement,
12
23
  QueryResult,
24
+ ArrowQueryResult,
25
+ json,
13
26
  get VERSION() {
14
27
  return Database.getVersion();
15
28
  },
package/index.mjs CHANGED
@@ -5,6 +5,8 @@ export const Database = lbug.Database;
5
5
  export const Connection = lbug.Connection;
6
6
  export const PreparedStatement = lbug.PreparedStatement;
7
7
  export const QueryResult = lbug.QueryResult;
8
+ export const ArrowQueryResult = lbug.ArrowQueryResult;
9
+ export const json = lbug.json;
8
10
  export const VERSION = lbug.VERSION;
9
11
  export const STORAGE_VERSION = lbug.STORAGE_VERSION;
10
12
  export default lbug;
package/lbug.d.ts CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * A nullable type that can be either T or null.
4
3
  */
@@ -22,6 +21,22 @@ export type ProgressCallback = (
22
21
  numPipelines: number
23
22
  ) => void;
24
23
 
24
+ /**
25
+ * Low-level pointer to an Arrow C Data Interface struct.
26
+ * Native producers can pass N-API External values; JavaScript callers that have
27
+ * raw addresses can pass them as bigint.
28
+ */
29
+ export type NativePointer = bigint | object;
30
+
31
+ /**
32
+ * Zero-copy CSR arrays returned by an Arrow query result.
33
+ */
34
+ export interface CSRResult {
35
+ indptr: BigUint64Array;
36
+ indices: BigUint64Array;
37
+ edgeIds: BigUint64Array | null;
38
+ }
39
+
25
40
  /**
26
41
  * Represents a node ID in the graph database.
27
42
  */
@@ -84,6 +99,7 @@ export type LbugValue =
84
99
  | RelValue
85
100
  | RecursiveRelValue
86
101
  | LbugValue[]
102
+ | Map<LbugValue, LbugValue>
87
103
  | { [key: string]: LbugValue };
88
104
 
89
105
  /**
@@ -102,8 +118,15 @@ export interface SystemConfig {
102
118
  autoCheckpoint?: boolean;
103
119
  /** Threshold for automatic checkpoints */
104
120
  checkpointThreshold?: number;
121
+ /** Whether node tables create the default primary-key hash index */
122
+ enableDefaultHashIndex?: boolean;
105
123
  }
106
124
 
125
+ /**
126
+ * Wrap a string or JavaScript value as a JSON-typed query parameter.
127
+ */
128
+ export function json(value: string | LbugValue): LbugValue;
129
+
107
130
  /**
108
131
  * Represents a Lbug database instance.
109
132
  */
@@ -117,6 +140,9 @@ export class Database {
117
140
  * @param maxDBSize Maximum size of the database in bytes
118
141
  * @param autoCheckpoint Whether to enable automatic checkpoints
119
142
  * @param checkpointThreshold Threshold for automatic checkpoints
143
+ * @param throwOnWalReplayFailure Whether WAL replay failures should throw
144
+ * @param enableChecksums Whether checksum validation is enabled
145
+ * @param enableDefaultHashIndex Whether node tables create the default primary-key hash index
120
146
  */
121
147
  constructor(
122
148
  databasePath?: string,
@@ -125,7 +151,10 @@ export class Database {
125
151
  readOnly?: boolean,
126
152
  maxDBSize?: number,
127
153
  autoCheckpoint?: boolean,
128
- checkpointThreshold?: number
154
+ checkpointThreshold?: number,
155
+ throwOnWalReplayFailure?: boolean,
156
+ enableChecksums?: boolean,
157
+ enableDefaultHashIndex?: boolean
129
158
  );
130
159
 
131
160
  /**
@@ -266,6 +295,56 @@ export class Connection {
266
295
  * @returns The query result(s)
267
296
  */
268
297
  querySync(statement: string): QueryResult | QueryResult[];
298
+
299
+ /**
300
+ * Execute a query with the native Arrow result collector.
301
+ * @param statement The statement to execute
302
+ * @param chunkSize Native Arrow chunk size
303
+ * @returns Promise that resolves to the Arrow query result
304
+ */
305
+ queryArrow(statement: string, chunkSize?: number): Promise<ArrowQueryResult>;
306
+
307
+ /**
308
+ * Execute a query synchronously with the native Arrow result collector.
309
+ * @param statement The statement to execute
310
+ * @param chunkSize Native Arrow chunk size
311
+ * @returns The Arrow query result
312
+ */
313
+ queryArrowSync(statement: string, chunkSize?: number): ArrowQueryResult;
314
+
315
+ /**
316
+ * Create an Arrow memory-backed node table from Arrow C Data Interface pointers.
317
+ * Ownership of schemaPtr and arraysPtr is transferred to Ladybug.
318
+ */
319
+ createArrowTableSync(
320
+ tableName: string,
321
+ schemaPtr: NativePointer,
322
+ arraysPtr: NativePointer | NativePointer[],
323
+ numArrays?: number
324
+ ): QueryResult;
325
+
326
+ /**
327
+ * Create an Arrow memory-backed relationship table from Arrow C Data Interface pointers.
328
+ * For flat layout (default): the Arrow table must contain endpoint columns named "from" and "to".
329
+ * For CSR layout: pass indptrSchemaPtr and indptrArraysPtr; dstColName names the destination column.
330
+ * Ownership of schemaPtr and arraysPtr is transferred to Ladybug.
331
+ */
332
+ createArrowRelTableSync(
333
+ tableName: string,
334
+ srcTableName: string,
335
+ dstTableName: string,
336
+ schemaPtr: NativePointer,
337
+ arraysPtr: NativePointer | NativePointer[],
338
+ numArrays?: number,
339
+ indptrSchemaPtr?: NativePointer | null,
340
+ indptrArraysPtr?: NativePointer | NativePointer[] | null,
341
+ numIndptrArrays?: number,
342
+ dstColName?: string): QueryResult;
343
+
344
+ /**
345
+ * Drop an Arrow memory-backed table and unregister its Arrow data.
346
+ */
347
+ dropArrowTableSync(tableName: string): QueryResult;
269
348
  }
270
349
 
271
350
  /**
@@ -279,6 +358,12 @@ export class PreparedStatement {
279
358
  */
280
359
  isSuccess(): boolean;
281
360
 
361
+ /**
362
+ * Check if the statement only performs read operations.
363
+ * @returns True if the prepared statement is read-only
364
+ */
365
+ isReadOnly(): boolean;
366
+
282
367
  /**
283
368
  * Get the error message if preparation failed.
284
369
  * @returns The error message or empty string if successful
@@ -384,6 +469,16 @@ export class QueryResult {
384
469
  close(): void;
385
470
  }
386
471
 
472
+ /**
473
+ * Represents an Arrow-native query result.
474
+ */
475
+ export class ArrowQueryResult extends QueryResult {
476
+ /**
477
+ * Get zero-copy native CSR arrays.
478
+ */
479
+ csr(): CSRResult;
480
+ }
481
+
387
482
  /**
388
483
  * Default export for the Lbug module.
389
484
  */
@@ -392,6 +487,8 @@ declare const lbug: {
392
487
  Connection: typeof Connection;
393
488
  PreparedStatement: typeof PreparedStatement;
394
489
  QueryResult: typeof QueryResult;
490
+ ArrowQueryResult: typeof ArrowQueryResult;
491
+ json: typeof json;
395
492
  VERSION: string;
396
493
  STORAGE_VERSION: bigint;
397
494
  };
package/lbugjs.node CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ladybugdb/core-darwin-arm64",
3
- "version": "0.17.0-dev.20260528",
3
+ "version": "0.17.0",
4
4
  "description": "An in-process property graph database management system built for query speed and scalability.",
5
5
  "os": [
6
6
  "darwin"
@@ -30,6 +30,14 @@ class PreparedStatement {
30
30
  return this._preparedStatement.isSuccess();
31
31
  }
32
32
 
33
+ /**
34
+ * Check if the prepared statement only performs read operations.
35
+ * @returns {Boolean} true if the prepared statement is read-only.
36
+ */
37
+ isReadOnly() {
38
+ return this._preparedStatement.isReadOnly();
39
+ }
40
+
33
41
  /**
34
42
  * Get the error message if the prepared statement is not successfully prepared.
35
43
  * @returns {String} the error message.
package/query_result.js CHANGED
@@ -239,4 +239,27 @@ class QueryResult {
239
239
  }
240
240
  }
241
241
 
242
+ class ArrowQueryResult extends QueryResult {
243
+ /**
244
+ * Internal constructor. Use `Connection.queryArrow` or `Connection.queryArrowSync`.
245
+ * @param {Connection} connection the connection object.
246
+ * @param {LbugNative.NodeQueryResult} queryResult the native query result object.
247
+ * @param {Number} chunkSize native Arrow result chunk size.
248
+ */
249
+ constructor(connection, queryResult, chunkSize) {
250
+ super(connection, queryResult);
251
+ this._chunkSize = chunkSize;
252
+ }
253
+
254
+ /**
255
+ * Get zero-copy native CSR arrays from an Arrow query result.
256
+ * @returns {{indptr: BigUint64Array, indices: BigUint64Array, edgeIds: BigUint64Array|null}}
257
+ */
258
+ csr() {
259
+ this._checkClosed();
260
+ return this._queryResult.getCSRSync();
261
+ }
262
+ }
263
+
242
264
  module.exports = QueryResult;
265
+ module.exports.ArrowQueryResult = ArrowQueryResult;