@ladybugdb/core-linux-arm64 0.15.2
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/LICENSE +21 -0
- package/README.md +69 -0
- package/connection.js +471 -0
- package/database.js +211 -0
- package/index.js +19 -0
- package/index.mjs +10 -0
- package/lbug.d.ts +399 -0
- package/lbug_native.js +25 -0
- package/lbugjs.node +0 -0
- package/package.json +29 -0
- package/prepared_statement.js +42 -0
- package/query_result.js +242 -0
package/database.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const LbugNative = require("./lbug_native.js");
|
|
4
|
+
|
|
5
|
+
class Database {
|
|
6
|
+
/**
|
|
7
|
+
* Initialize a new Database object. Note that the initialization is done
|
|
8
|
+
* lazily, so the database file is not opened until the first query is
|
|
9
|
+
* executed. To initialize the database immediately, call the `init()`
|
|
10
|
+
* function on the returned object.
|
|
11
|
+
*
|
|
12
|
+
* @param {String} databasePath path to the database file. If the path is not specified, or empty, or equal to
|
|
13
|
+
`:memory:`, the database will be created in memory.
|
|
14
|
+
* @param {Number} bufferManagerSize size of the buffer manager in bytes.
|
|
15
|
+
* @param {Boolean} enableCompression whether to enable compression.
|
|
16
|
+
* @param {Boolean} readOnly if true, database will be opened in read-only mode.
|
|
17
|
+
* @param {Number} maxDBSize maximum size of the database file in bytes. Note that
|
|
18
|
+
* this is introduced temporarily for now to get around with the default 8TB mmap
|
|
19
|
+
* address space limit some environment.
|
|
20
|
+
* @param {Boolean} autoCheckpoint If true, the database will automatically checkpoint when the size of
|
|
21
|
+
* the WAL file exceeds the checkpoint threshold.
|
|
22
|
+
* @param {Number} checkpointThreshold The threshold of the WAL file size in bytes. When the size of the
|
|
23
|
+
* WAL file exceeds this threshold, the database will checkpoint if autoCheckpoint is true.
|
|
24
|
+
* @param {Boolean} throwOnWalReplayFailure If true, any WAL replaying failure when loading the database
|
|
25
|
+
* will throw an error. Otherwise, Lbug will silently ignore the failure and replay up to where
|
|
26
|
+
* the error occured.
|
|
27
|
+
* @param {Boolean} enableChecksums If true, the database will use checksums to detect corruption in the
|
|
28
|
+
* WAL file.
|
|
29
|
+
*/
|
|
30
|
+
constructor(
|
|
31
|
+
databasePath,
|
|
32
|
+
bufferManagerSize = 0,
|
|
33
|
+
enableCompression = true,
|
|
34
|
+
readOnly = false,
|
|
35
|
+
maxDBSize = 0,
|
|
36
|
+
autoCheckpoint = true,
|
|
37
|
+
checkpointThreshold = -1,
|
|
38
|
+
throwOnWalReplayFailure = true,
|
|
39
|
+
enableChecksums = true,
|
|
40
|
+
) {
|
|
41
|
+
if (!databasePath) {
|
|
42
|
+
databasePath = ":memory:";
|
|
43
|
+
}
|
|
44
|
+
else if (typeof databasePath !== "string") {
|
|
45
|
+
throw new Error("Database path must be a string.");
|
|
46
|
+
}
|
|
47
|
+
if (typeof bufferManagerSize !== "number" || bufferManagerSize < 0) {
|
|
48
|
+
throw new Error("Buffer manager size must be a positive integer.");
|
|
49
|
+
}
|
|
50
|
+
if (typeof maxDBSize !== "number" || maxDBSize < 0) {
|
|
51
|
+
throw new Error("Max DB size must be a positive integer.");
|
|
52
|
+
}
|
|
53
|
+
if (typeof checkpointThreshold !== "number" || maxDBSize < -1) {
|
|
54
|
+
throw new Error("Checkpoint threshold must be a positive integer.");
|
|
55
|
+
}
|
|
56
|
+
bufferManagerSize = Math.floor(bufferManagerSize);
|
|
57
|
+
maxDBSize = Math.floor(maxDBSize);
|
|
58
|
+
checkpointThreshold = Math.floor(checkpointThreshold);
|
|
59
|
+
this._database = new LbugNative.NodeDatabase(
|
|
60
|
+
databasePath,
|
|
61
|
+
bufferManagerSize,
|
|
62
|
+
enableCompression,
|
|
63
|
+
readOnly,
|
|
64
|
+
maxDBSize,
|
|
65
|
+
autoCheckpoint,
|
|
66
|
+
checkpointThreshold,
|
|
67
|
+
throwOnWalReplayFailure,
|
|
68
|
+
enableChecksums
|
|
69
|
+
);
|
|
70
|
+
this._isInitialized = false;
|
|
71
|
+
this._initPromise = null;
|
|
72
|
+
this._isClosed = false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Get the version of the library.
|
|
77
|
+
* @returns {String} the version of the library.
|
|
78
|
+
*/
|
|
79
|
+
static getVersion() {
|
|
80
|
+
return LbugNative.NodeDatabase.getVersion();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Get the storage version of the library.
|
|
85
|
+
* @returns {Number} the storage version of the library.
|
|
86
|
+
*/
|
|
87
|
+
static getStorageVersion() {
|
|
88
|
+
return LbugNative.NodeDatabase.getStorageVersion();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Initialize the database. Calling this function is optional, as the
|
|
93
|
+
* database is initialized automatically when the first query is executed.
|
|
94
|
+
*/
|
|
95
|
+
async init() {
|
|
96
|
+
if (!this._isInitialized) {
|
|
97
|
+
if (!this._initPromise) {
|
|
98
|
+
this._initPromise = new Promise((resolve, reject) => {
|
|
99
|
+
this._database.initAsync((err) => {
|
|
100
|
+
if (err) {
|
|
101
|
+
reject(err);
|
|
102
|
+
} else {
|
|
103
|
+
try {
|
|
104
|
+
this._isInitialized = true;
|
|
105
|
+
} catch (e) {
|
|
106
|
+
return reject(e);
|
|
107
|
+
}
|
|
108
|
+
resolve();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
await this._initPromise;
|
|
114
|
+
this._initPromise = null;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Initialize the database synchronously. Calling this function is optional, as the
|
|
120
|
+
* database is initialized automatically when the first query is executed. This function
|
|
121
|
+
* may block the main thread, so use it with caution.
|
|
122
|
+
*/
|
|
123
|
+
initSync() {
|
|
124
|
+
if (this._initPromise) {
|
|
125
|
+
throw new Error("There is an ongoing asynchronous initialization. Please wait for it to finish.");
|
|
126
|
+
}
|
|
127
|
+
if (this._isInitialized) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
this._database.initSync();
|
|
131
|
+
this._isInitialized = true;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Internal function to get the underlying native database object.
|
|
136
|
+
* @returns {LbugNative.NodeDatabase} the underlying native database.
|
|
137
|
+
* @throws {Error} if the database is closed.
|
|
138
|
+
*/
|
|
139
|
+
async _getDatabase() {
|
|
140
|
+
if (this._isClosed) {
|
|
141
|
+
throw new Error("Database is closed.");
|
|
142
|
+
}
|
|
143
|
+
await this.init();
|
|
144
|
+
return this._database;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Internal function to get the underlying native database object synchronously.
|
|
149
|
+
* @returns {LbugNative.NodeDatabase} the underlying native database.
|
|
150
|
+
* @throws {Error} if the database is closed.
|
|
151
|
+
*/
|
|
152
|
+
_getDatabaseSync() {
|
|
153
|
+
if (this._isClosed) {
|
|
154
|
+
throw new Error("Database is closed.");
|
|
155
|
+
}
|
|
156
|
+
if (!this._isInitialized) {
|
|
157
|
+
this.initSync();
|
|
158
|
+
}
|
|
159
|
+
return this._database;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Close the database.
|
|
164
|
+
*/
|
|
165
|
+
async close() {
|
|
166
|
+
if (this._isClosed) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (!this._isInitialized) {
|
|
170
|
+
if (this._initPromise) {
|
|
171
|
+
// Database is initializing, wait for it to finish first.
|
|
172
|
+
await this._initPromise;
|
|
173
|
+
} else {
|
|
174
|
+
// Database is not initialized, simply mark it as closed and initialized.
|
|
175
|
+
this._isInitialized = true;
|
|
176
|
+
this._isClosed = true;
|
|
177
|
+
delete this._database;
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
// Database is initialized, close it.
|
|
182
|
+
this._database.close();
|
|
183
|
+
delete this._database;
|
|
184
|
+
this._isClosed = true;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Close the database synchronously.
|
|
189
|
+
* @throws {Error} if there is an ongoing asynchronous initialization.
|
|
190
|
+
*/
|
|
191
|
+
closeSync() {
|
|
192
|
+
if (this._isClosed) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (!this._isInitialized) {
|
|
196
|
+
if (this._initPromise) {
|
|
197
|
+
throw new Error("There is an ongoing asynchronous initialization. Please wait for it to finish.");
|
|
198
|
+
} else {
|
|
199
|
+
this._isInitialized = true;
|
|
200
|
+
this._isClosed = true;
|
|
201
|
+
delete this._database;
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
this._database.close();
|
|
206
|
+
delete this._database;
|
|
207
|
+
this._isClosed = true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = Database;
|
package/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const Connection = require("./connection.js");
|
|
4
|
+
const Database = require("./database.js");
|
|
5
|
+
const PreparedStatement = require("./prepared_statement.js");
|
|
6
|
+
const QueryResult = require("./query_result.js");
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
Connection,
|
|
10
|
+
Database,
|
|
11
|
+
PreparedStatement,
|
|
12
|
+
QueryResult,
|
|
13
|
+
get VERSION() {
|
|
14
|
+
return Database.getVersion();
|
|
15
|
+
},
|
|
16
|
+
get STORAGE_VERSION() {
|
|
17
|
+
return Database.getStorageVersion();
|
|
18
|
+
},
|
|
19
|
+
};
|
package/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import lbug from "./index.js";
|
|
2
|
+
|
|
3
|
+
// Re-export everything from the CommonJS module
|
|
4
|
+
export const Database = lbug.Database;
|
|
5
|
+
export const Connection = lbug.Connection;
|
|
6
|
+
export const PreparedStatement = lbug.PreparedStatement;
|
|
7
|
+
export const QueryResult = lbug.QueryResult;
|
|
8
|
+
export const VERSION = lbug.VERSION;
|
|
9
|
+
export const STORAGE_VERSION = lbug.STORAGE_VERSION;
|
|
10
|
+
export default lbug;
|
package/lbug.d.ts
ADDED
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* A nullable type that can be either T or null.
|
|
4
|
+
*/
|
|
5
|
+
export type Nullable<T> = T | null;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A callback function pattern used throughout the API.
|
|
9
|
+
* @template T The type of the result value (defaults to void)
|
|
10
|
+
*/
|
|
11
|
+
export type Callback<T = void> = (error: Error | null, result?: T) => void;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Callback for query execution progress updates.
|
|
15
|
+
* @param pipelineProgress Progress of the current pipeline (0-100)
|
|
16
|
+
* @param numPipelinesFinished Number of pipelines completed
|
|
17
|
+
* @param numPipelines Total number of pipelines
|
|
18
|
+
*/
|
|
19
|
+
export type ProgressCallback = (
|
|
20
|
+
pipelineProgress: number,
|
|
21
|
+
numPipelinesFinished: number,
|
|
22
|
+
numPipelines: number
|
|
23
|
+
) => void;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Represents a node ID in the graph database.
|
|
27
|
+
*/
|
|
28
|
+
export interface NodeID {
|
|
29
|
+
/** The offset of the node in its table */
|
|
30
|
+
offset: number;
|
|
31
|
+
/** The table ID the node belongs to */
|
|
32
|
+
table: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Represents a node value in the graph.
|
|
37
|
+
*/
|
|
38
|
+
export interface NodeValue {
|
|
39
|
+
/** The label of the node (type) */
|
|
40
|
+
_label: string | null;
|
|
41
|
+
/** The ID of the node */
|
|
42
|
+
_id: NodeID | null;
|
|
43
|
+
/** Additional properties of the node */
|
|
44
|
+
[key: string]: any;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Represents a relationship (edge) value in the graph.
|
|
49
|
+
*/
|
|
50
|
+
export interface RelValue {
|
|
51
|
+
/** The source node ID */
|
|
52
|
+
_src: NodeID | null;
|
|
53
|
+
/** The destination node ID */
|
|
54
|
+
_dst: NodeID | null;
|
|
55
|
+
/** The relationship type/label */
|
|
56
|
+
_label: string | null;
|
|
57
|
+
/** The relationship ID */
|
|
58
|
+
_id: any;
|
|
59
|
+
/** Additional properties of the relationship */
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Represents a recursive relationship value (path) in the graph.
|
|
65
|
+
*/
|
|
66
|
+
export interface RecursiveRelValue {
|
|
67
|
+
/** Array of nodes in the path */
|
|
68
|
+
_nodes: any[];
|
|
69
|
+
/** Array of relationships in the path */
|
|
70
|
+
_rels: any[];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Union type representing all possible value types in Lbug.
|
|
75
|
+
*/
|
|
76
|
+
export type LbugValue =
|
|
77
|
+
| null
|
|
78
|
+
| boolean
|
|
79
|
+
| number
|
|
80
|
+
| bigint
|
|
81
|
+
| string
|
|
82
|
+
| Date
|
|
83
|
+
| NodeValue
|
|
84
|
+
| RelValue
|
|
85
|
+
| RecursiveRelValue
|
|
86
|
+
| LbugValue[]
|
|
87
|
+
| { [key: string]: LbugValue };
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Configuration options for the database system.
|
|
91
|
+
*/
|
|
92
|
+
export interface SystemConfig {
|
|
93
|
+
/** Size of the buffer pool in bytes */
|
|
94
|
+
bufferPoolSize?: number;
|
|
95
|
+
/** Whether to enable compression */
|
|
96
|
+
enableCompression?: boolean;
|
|
97
|
+
/** Whether to open the database in read-only mode */
|
|
98
|
+
readOnly?: boolean;
|
|
99
|
+
/** Maximum size of the database in bytes */
|
|
100
|
+
maxDBSize?: number;
|
|
101
|
+
/** Whether to enable automatic checkpoints */
|
|
102
|
+
autoCheckpoint?: boolean;
|
|
103
|
+
/** Threshold for automatic checkpoints */
|
|
104
|
+
checkpointThreshold?: number;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Represents a Lbug database instance.
|
|
109
|
+
*/
|
|
110
|
+
export class Database {
|
|
111
|
+
/**
|
|
112
|
+
* Constructs a new Database instance.
|
|
113
|
+
* @param databasePath Path to the database directory (defaults to ":memory:")
|
|
114
|
+
* @param bufferManagerSize Size of the buffer manager in bytes
|
|
115
|
+
* @param enableCompression Whether to enable compression
|
|
116
|
+
* @param readOnly Whether to open in read-only mode
|
|
117
|
+
* @param maxDBSize Maximum size of the database in bytes
|
|
118
|
+
* @param autoCheckpoint Whether to enable automatic checkpoints
|
|
119
|
+
* @param checkpointThreshold Threshold for automatic checkpoints
|
|
120
|
+
*/
|
|
121
|
+
constructor(
|
|
122
|
+
databasePath?: string,
|
|
123
|
+
bufferManagerSize?: number,
|
|
124
|
+
enableCompression?: boolean,
|
|
125
|
+
readOnly?: boolean,
|
|
126
|
+
maxDBSize?: number,
|
|
127
|
+
autoCheckpoint?: boolean,
|
|
128
|
+
checkpointThreshold?: number
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Initialize the database. Calling this function is optional, as the
|
|
133
|
+
* database is initialized automatically when the first query is executed.
|
|
134
|
+
* @returns Promise that resolves when initialization completes
|
|
135
|
+
*/
|
|
136
|
+
init(): Promise<void>;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Initialize the database synchronously. Calling this function is optional, as the
|
|
140
|
+
* database is initialized automatically when the first query is executed. This function
|
|
141
|
+
* may block the main thread, so use it with caution.
|
|
142
|
+
*/
|
|
143
|
+
initSync(): void;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Close the database and release resources.
|
|
147
|
+
* @returns Promise that resolves when database is closed
|
|
148
|
+
*/
|
|
149
|
+
close(): Promise<void>;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Close the database synchronously.
|
|
153
|
+
*/
|
|
154
|
+
closeSync(): void;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Get the version of the Lbug library.
|
|
158
|
+
* @returns The version string of the library
|
|
159
|
+
*/
|
|
160
|
+
static getVersion(): string;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get the storage version of the Lbug library.
|
|
164
|
+
* @returns The storage version of the library
|
|
165
|
+
*/
|
|
166
|
+
static getStorageVersion(): number;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Represents a connection to a Lbug database.
|
|
171
|
+
*/
|
|
172
|
+
export class Connection {
|
|
173
|
+
/**
|
|
174
|
+
* Creates a new connection to the specified database.
|
|
175
|
+
* @param database The database instance to connect to
|
|
176
|
+
* @param numThreads Optional maximum number of threads for query execution
|
|
177
|
+
*/
|
|
178
|
+
constructor(database: Database, numThreads?: number);
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Initialize the connection.
|
|
182
|
+
* @returns Promise that resolves when initialization completes
|
|
183
|
+
*/
|
|
184
|
+
init(): Promise<void>;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Initialize the connection synchronously. This function may block the main thread, so use it with caution.
|
|
188
|
+
*/
|
|
189
|
+
initSync(): void;
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Set the maximum number of threads for query execution.
|
|
193
|
+
* @param numThreads The number of threads to use
|
|
194
|
+
*/
|
|
195
|
+
setMaxNumThreadForExec(numThreads: number): void;
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Set the query timeout in milliseconds.
|
|
199
|
+
* @param timeoutInMs Timeout in milliseconds
|
|
200
|
+
*/
|
|
201
|
+
setQueryTimeout(timeoutInMs: number): void;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Close the connection.
|
|
205
|
+
* @returns Promise that resolves when connection is closed
|
|
206
|
+
*/
|
|
207
|
+
close(): Promise<void>;
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Close the connection synchronously.
|
|
211
|
+
*/
|
|
212
|
+
closeSync(): void;
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Execute a prepared statement.
|
|
216
|
+
* @param preparedStatement The prepared statement to execute
|
|
217
|
+
* @param params Parameters for the query as a plain object
|
|
218
|
+
* @param progressCallback Optional progress callback
|
|
219
|
+
* @returns Promise that resolves to the query result(s)
|
|
220
|
+
*/
|
|
221
|
+
execute(
|
|
222
|
+
preparedStatement: PreparedStatement,
|
|
223
|
+
params?: Record<string, LbugValue>,
|
|
224
|
+
progressCallback?: ProgressCallback
|
|
225
|
+
): Promise<QueryResult | QueryResult[]>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Execute a prepared statement synchronously.
|
|
229
|
+
* @param preparedStatement The prepared statement to execute
|
|
230
|
+
* @param params Parameters for the query as a plain object
|
|
231
|
+
* @returns The query result(s)
|
|
232
|
+
*/
|
|
233
|
+
executeSync(
|
|
234
|
+
preparedStatement: PreparedStatement,
|
|
235
|
+
params?: Record<string, LbugValue>
|
|
236
|
+
): QueryResult | QueryResult[];
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Prepare a statement for execution.
|
|
240
|
+
* @param statement The statement to prepare
|
|
241
|
+
* @returns Promise that resolves to the prepared statement
|
|
242
|
+
*/
|
|
243
|
+
prepare(statement: string): Promise<PreparedStatement>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Prepare a statement for execution synchronously.
|
|
247
|
+
* @param statement The statement to prepare
|
|
248
|
+
* @returns The prepared statement
|
|
249
|
+
*/
|
|
250
|
+
prepareSync(statement: string): PreparedStatement;
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Execute a query.
|
|
254
|
+
* @param statement The statement to execute
|
|
255
|
+
* @param progressCallback Optional progress callback
|
|
256
|
+
* @returns Promise that resolves to the query result(s)
|
|
257
|
+
*/
|
|
258
|
+
query(
|
|
259
|
+
statement: string,
|
|
260
|
+
progressCallback?: ProgressCallback
|
|
261
|
+
): Promise<QueryResult | QueryResult[]>;
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Execute a query synchronously.
|
|
265
|
+
* @param statement The statement to execute
|
|
266
|
+
* @returns The query result(s)
|
|
267
|
+
*/
|
|
268
|
+
querySync(statement: string): QueryResult | QueryResult[];
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Represents a prepared statement for efficient query execution.
|
|
273
|
+
* Note: This class is created internally by Connection.prepare() methods.
|
|
274
|
+
*/
|
|
275
|
+
export class PreparedStatement {
|
|
276
|
+
/**
|
|
277
|
+
* Check if the statement was prepared successfully.
|
|
278
|
+
* @returns True if preparation was successful
|
|
279
|
+
*/
|
|
280
|
+
isSuccess(): boolean;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Get the error message if preparation failed.
|
|
284
|
+
* @returns The error message or empty string if successful
|
|
285
|
+
*/
|
|
286
|
+
getErrorMessage(): string;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Represents the results of a query execution.
|
|
291
|
+
* Note: This class is created internally by Connection query methods.
|
|
292
|
+
*/
|
|
293
|
+
export class QueryResult {
|
|
294
|
+
/**
|
|
295
|
+
* Reset the iterator for reading results.
|
|
296
|
+
*/
|
|
297
|
+
resetIterator(): void;
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Check if there are more rows to read.
|
|
301
|
+
* @returns True if more rows are available
|
|
302
|
+
*/
|
|
303
|
+
hasNext(): boolean;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Get the number of tuples (rows) in the result.
|
|
307
|
+
* @returns The number of rows
|
|
308
|
+
*/
|
|
309
|
+
getNumTuples(): number;
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* Get the next row.
|
|
313
|
+
* @returns Promise that resolves to the next row or null if no more rows
|
|
314
|
+
*/
|
|
315
|
+
getNext(): Promise<Record<string, LbugValue> | null>;
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* Get the next row synchronously.
|
|
319
|
+
* @returns The next row or null if no more rows
|
|
320
|
+
*/
|
|
321
|
+
getNextSync(): Record<string, LbugValue> | null;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Iterate through the query result with callback functions.
|
|
325
|
+
* @param resultCallback Callback function called for each row
|
|
326
|
+
* @param doneCallback Callback function called when iteration is done
|
|
327
|
+
* @param errorCallback Callback function called when there is an error
|
|
328
|
+
*/
|
|
329
|
+
each(
|
|
330
|
+
resultCallback: (row: Record<string, LbugValue>) => void,
|
|
331
|
+
doneCallback: () => void,
|
|
332
|
+
errorCallback: (error: Error) => void
|
|
333
|
+
): void;
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Get all rows of the query result.
|
|
337
|
+
* @returns Promise that resolves to all rows
|
|
338
|
+
*/
|
|
339
|
+
getAll(): Promise<Record<string, LbugValue>[]>;
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Get all rows of the query result synchronously.
|
|
343
|
+
* @returns All rows of the query result
|
|
344
|
+
*/
|
|
345
|
+
getAllSync(): Record<string, LbugValue>[];
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Get all rows of the query result with callback functions.
|
|
349
|
+
* @param resultCallback Callback function called with all rows
|
|
350
|
+
* @param errorCallback Callback function called when there is an error
|
|
351
|
+
*/
|
|
352
|
+
all(
|
|
353
|
+
resultCallback: (rows: Record<string, LbugValue>[]) => void,
|
|
354
|
+
errorCallback: (error: Error) => void
|
|
355
|
+
): void;
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Get the column data types.
|
|
359
|
+
* @returns Promise that resolves to array of data type strings
|
|
360
|
+
*/
|
|
361
|
+
getColumnDataTypes(): Promise<string[]>;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* Get the column data types synchronously.
|
|
365
|
+
* @returns Array of data type strings
|
|
366
|
+
*/
|
|
367
|
+
getColumnDataTypesSync(): string[];
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Get the column names.
|
|
371
|
+
* @returns Promise that resolves to array of column names
|
|
372
|
+
*/
|
|
373
|
+
getColumnNames(): Promise<string[]>;
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Get the column names synchronously.
|
|
377
|
+
* @returns Array of column names
|
|
378
|
+
*/
|
|
379
|
+
getColumnNamesSync(): string[];
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* Close the result set and release resources.
|
|
383
|
+
*/
|
|
384
|
+
close(): void;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Default export for the Lbug module.
|
|
389
|
+
*/
|
|
390
|
+
declare const lbug: {
|
|
391
|
+
Database: typeof Database;
|
|
392
|
+
Connection: typeof Connection;
|
|
393
|
+
PreparedStatement: typeof PreparedStatement;
|
|
394
|
+
QueryResult: typeof QueryResult;
|
|
395
|
+
VERSION: string;
|
|
396
|
+
STORAGE_VERSION: bigint;
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
export default lbug;
|
package/lbug_native.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is a customized loader for the lbugjs.node native module.
|
|
3
|
+
* It is used to load the native module with the correct flags on Linux so that
|
|
4
|
+
* extension loading works correctly.
|
|
5
|
+
* @module lbug_native
|
|
6
|
+
* @private
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const process = require("process");
|
|
10
|
+
const constants = require("constants");
|
|
11
|
+
const join = require("path").join;
|
|
12
|
+
|
|
13
|
+
const lbugNativeModule = { exports: {} };
|
|
14
|
+
const modulePath = join(__dirname, "lbugjs.node");
|
|
15
|
+
if (process.platform === "linux") {
|
|
16
|
+
process.dlopen(
|
|
17
|
+
lbugNativeModule,
|
|
18
|
+
modulePath,
|
|
19
|
+
constants.RTLD_LAZY | constants.RTLD_GLOBAL
|
|
20
|
+
);
|
|
21
|
+
} else {
|
|
22
|
+
process.dlopen(lbugNativeModule, modulePath);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = lbugNativeModule.exports;
|
package/lbugjs.node
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ladybugdb/core-linux-arm64",
|
|
3
|
+
"version": "0.15.2",
|
|
4
|
+
"description": "An in-process property graph database management system built for query speed and scalability.",
|
|
5
|
+
"os": [
|
|
6
|
+
"linux"
|
|
7
|
+
],
|
|
8
|
+
"cpu": [
|
|
9
|
+
"arm64"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/LadybugDB/ladybug.git"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"connection.js",
|
|
18
|
+
"database.js",
|
|
19
|
+
"index.js",
|
|
20
|
+
"index.mjs",
|
|
21
|
+
"lbug.d.ts",
|
|
22
|
+
"lbug_native.js",
|
|
23
|
+
"prepared_statement.js",
|
|
24
|
+
"query_result.js",
|
|
25
|
+
"lbugjs.node",
|
|
26
|
+
"LICENSE",
|
|
27
|
+
"README.md"
|
|
28
|
+
]
|
|
29
|
+
}
|