@stoolap/node 0.3.1

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.
Files changed (5) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +411 -0
  3. package/index.d.ts +176 -0
  4. package/index.js +584 -0
  5. package/package.json +60 -0
package/index.d.ts ADDED
@@ -0,0 +1,176 @@
1
+ /* auto-generated by NAPI-RS */
2
+ /* eslint-disable */
3
+
4
+ export interface RunResult {
5
+ changes: number
6
+ }
7
+
8
+ export declare class Database {
9
+ /**
10
+ * Open a database. Returns a Promise that resolves to a Database instance.
11
+ *
12
+ * Accepts:
13
+ * - `:memory:` or empty string for in-memory database
14
+ * - `memory://` for in-memory database
15
+ * - `file:///path/to/db` for file-based database
16
+ * - Bare path like `./mydb` for file-based database
17
+ */
18
+ static open(path: string): Promise<Database>
19
+ /**
20
+ * Execute a DDL/DML statement. Returns Promise<{ changes: number }>.
21
+ *
22
+ * @param sql - SQL statement
23
+ * @param params - Optional: Array for positional ($1, $2) or Object for named (:key)
24
+ */
25
+ execute(sql: string, params?: any[] | Record<string, any>): Promise<RunResult>
26
+ /**
27
+ * Execute one or more SQL statements separated by semicolons.
28
+ * Returns Promise<void>.
29
+ */
30
+ exec(sql: string): Promise<void>
31
+ /**
32
+ * Query rows. Returns Promise<Array<Object>>.
33
+ *
34
+ * Each row is an object with column names as keys.
35
+ */
36
+ query(sql: string, params?: any[] | Record<string, any>): Promise<Record<string, any>[]>
37
+ /** Query a single row. Returns Promise<Object | null>. */
38
+ queryOne(sql: string, params?: any[] | Record<string, any>): Promise<Record<string, any> | null>
39
+ /**
40
+ * Query rows in raw format. Returns Promise<{ columns: string[], rows: any[][] }>.
41
+ *
42
+ * Faster than query() — skips per-row object creation.
43
+ */
44
+ queryRaw(sql: string, params?: any[] | Record<string, any>): Promise<{ columns: string[], rows: any[][] }>
45
+ /**
46
+ * Execute a DML statement synchronously. Returns { changes: number }.
47
+ *
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>
83
+ }
84
+ export type JsDatabase = Database
85
+
86
+ export declare class PreparedStatement {
87
+ /** Execute the statement (DML). Returns Promise<{ changes: number }>. */
88
+ execute(params?: any[] | Record<string, any>): Promise<RunResult>
89
+ /** Query rows. Returns Promise<Array<Object>>. */
90
+ query(params?: any[] | Record<string, any>): Promise<Record<string, any>[]>
91
+ /** Query single row. Returns Promise<Object | null>. */
92
+ queryOne(params?: any[] | Record<string, any>): Promise<Record<string, any> | null>
93
+ /** Query rows in raw format. Returns Promise<{ columns: string[], rows: any[][] }>. */
94
+ queryRaw(params?: any[] | Record<string, any>): Promise<{ columns: string[], rows: any[][] }>
95
+ /** 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
120
+ }
121
+ export type JsPreparedStatement = PreparedStatement
122
+
123
+ 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[][] }>
144
+ /** Commit the transaction. Returns Promise<void>. */
145
+ commit(): Promise<void>
146
+ /** Rollback the transaction. Returns Promise<void>. */
147
+ rollback(): Promise<void>
148
+ /** 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
175
+ }
176
+ export type JsTransaction = Transaction