@tursodatabase/serverless 1.1.1 → 1.1.2-pre.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.
- package/dist/compat/index.cjs +885 -0
- package/dist/{compat.d.ts → compat/index.d.cts} +13 -11
- package/dist/compat/index.d.ts +147 -1
- package/dist/compat/index.js +882 -1
- package/dist/index.cjs +1064 -0
- package/dist/index.d.cts +516 -0
- package/dist/index.d.ts +516 -5
- package/dist/index.js +1056 -6
- package/package.json +26 -10
- package/dist/async-lock.d.ts +0 -6
- package/dist/async-lock.js +0 -22
- package/dist/compat.js +0 -395
- package/dist/connection.d.ts +0 -197
- package/dist/connection.js +0 -312
- package/dist/error.d.ts +0 -19
- package/dist/error.js +0 -24
- package/dist/protocol.d.ts +0 -120
- package/dist/protocol.js +0 -206
- package/dist/session.d.ts +0 -93
- package/dist/session.js +0 -341
- package/dist/statement.d.ts +0 -161
- package/dist/statement.js +0 -308
package/dist/session.d.ts
DELETED
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { type CursorResponse, type CursorEntry, type DescribeResult, type QueryOptions } from './protocol.js';
|
|
2
|
-
/**
|
|
3
|
-
* Configuration options for a session.
|
|
4
|
-
*/
|
|
5
|
-
export interface SessionConfig {
|
|
6
|
-
/** Database URL */
|
|
7
|
-
url: string;
|
|
8
|
-
/** Authentication token (optional for local development with turso dev) */
|
|
9
|
-
authToken?: string;
|
|
10
|
-
/**
|
|
11
|
-
* Encryption key for the remote database (base64 encoded)
|
|
12
|
-
* to enable access to encrypted Turso Cloud databases.
|
|
13
|
-
*/
|
|
14
|
-
remoteEncryptionKey?: string;
|
|
15
|
-
/** Default maximum query execution time in milliseconds before interruption. */
|
|
16
|
-
defaultQueryTimeout?: number;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* A database session that manages the connection state and baton.
|
|
20
|
-
*
|
|
21
|
-
* Each session maintains its own connection state and can execute SQL statements
|
|
22
|
-
* independently without interfering with other sessions.
|
|
23
|
-
*/
|
|
24
|
-
export declare class Session {
|
|
25
|
-
private config;
|
|
26
|
-
private baton;
|
|
27
|
-
private baseUrl;
|
|
28
|
-
constructor(config: SessionConfig);
|
|
29
|
-
private createAbortSignal;
|
|
30
|
-
/**
|
|
31
|
-
* Describe a SQL statement to get its column metadata.
|
|
32
|
-
*
|
|
33
|
-
* @param sql - The SQL statement to describe
|
|
34
|
-
* @returns Promise resolving to the statement description
|
|
35
|
-
*/
|
|
36
|
-
describe(sql: string, queryOptions?: QueryOptions): Promise<DescribeResult>;
|
|
37
|
-
/**
|
|
38
|
-
* Execute a SQL statement and return all results.
|
|
39
|
-
*
|
|
40
|
-
* @param sql - The SQL statement to execute
|
|
41
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
42
|
-
* @param safeIntegers - Whether to return integers as BigInt
|
|
43
|
-
* @returns Promise resolving to the complete result set
|
|
44
|
-
*/
|
|
45
|
-
execute(sql: string, args?: any[] | Record<string, any>, safeIntegers?: boolean, queryOptions?: QueryOptions): Promise<any>;
|
|
46
|
-
/**
|
|
47
|
-
* Execute a SQL statement and return the raw response and entries.
|
|
48
|
-
*
|
|
49
|
-
* @param sql - The SQL statement to execute
|
|
50
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
51
|
-
* @returns Promise resolving to the raw response and cursor entries
|
|
52
|
-
*/
|
|
53
|
-
executeRaw(sql: string, args?: any[] | Record<string, any>, queryOptions?: QueryOptions): Promise<{
|
|
54
|
-
response: CursorResponse;
|
|
55
|
-
entries: AsyncGenerator<CursorEntry>;
|
|
56
|
-
}>;
|
|
57
|
-
/**
|
|
58
|
-
* Process cursor entries into a structured result.
|
|
59
|
-
*
|
|
60
|
-
* @param entries - Async generator of cursor entries
|
|
61
|
-
* @returns Promise resolving to the processed result
|
|
62
|
-
*/
|
|
63
|
-
processCursorEntries(entries: AsyncGenerator<CursorEntry>, safeIntegers?: boolean): Promise<any>;
|
|
64
|
-
/**
|
|
65
|
-
* Create a row object with both array and named property access.
|
|
66
|
-
*
|
|
67
|
-
* @param values - Array of column values
|
|
68
|
-
* @param columns - Array of column names
|
|
69
|
-
* @returns Row object with dual access patterns
|
|
70
|
-
*/
|
|
71
|
-
createRowObject(values: any[], columns: string[]): any;
|
|
72
|
-
/**
|
|
73
|
-
* Execute multiple SQL statements in a batch.
|
|
74
|
-
*
|
|
75
|
-
* @param statements - Array of SQL statements to execute
|
|
76
|
-
* @returns Promise resolving to batch execution results
|
|
77
|
-
*/
|
|
78
|
-
batch(statements: string[], queryOptions?: QueryOptions): Promise<any>;
|
|
79
|
-
/**
|
|
80
|
-
* Execute a sequence of SQL statements separated by semicolons.
|
|
81
|
-
*
|
|
82
|
-
* @param sql - SQL string containing multiple statements separated by semicolons
|
|
83
|
-
* @returns Promise resolving when all statements are executed
|
|
84
|
-
*/
|
|
85
|
-
sequence(sql: string, queryOptions?: QueryOptions): Promise<void>;
|
|
86
|
-
/**
|
|
87
|
-
* Close the session.
|
|
88
|
-
*
|
|
89
|
-
* This sends a close request to the server to properly clean up the stream
|
|
90
|
-
* before resetting the local state.
|
|
91
|
-
*/
|
|
92
|
-
close(): Promise<void>;
|
|
93
|
-
}
|
package/dist/session.js
DELETED
|
@@ -1,341 +0,0 @@
|
|
|
1
|
-
import { executeCursor, executePipeline, encodeValue, decodeValue } from './protocol.js';
|
|
2
|
-
import { DatabaseError } from './error.js';
|
|
3
|
-
function normalizeUrl(url) {
|
|
4
|
-
return url.replace(/^libsql:\/\//, 'https://');
|
|
5
|
-
}
|
|
6
|
-
function isValidIdentifier(str) {
|
|
7
|
-
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(str);
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* A database session that manages the connection state and baton.
|
|
11
|
-
*
|
|
12
|
-
* Each session maintains its own connection state and can execute SQL statements
|
|
13
|
-
* independently without interfering with other sessions.
|
|
14
|
-
*/
|
|
15
|
-
export class Session {
|
|
16
|
-
constructor(config) {
|
|
17
|
-
this.baton = null;
|
|
18
|
-
this.config = config;
|
|
19
|
-
this.baseUrl = normalizeUrl(config.url);
|
|
20
|
-
}
|
|
21
|
-
createAbortSignal(queryOptions) {
|
|
22
|
-
const timeout = queryOptions?.queryTimeout ?? this.config.defaultQueryTimeout;
|
|
23
|
-
if (timeout != null && timeout > 0) {
|
|
24
|
-
return AbortSignal.timeout(timeout);
|
|
25
|
-
}
|
|
26
|
-
return undefined;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Describe a SQL statement to get its column metadata.
|
|
30
|
-
*
|
|
31
|
-
* @param sql - The SQL statement to describe
|
|
32
|
-
* @returns Promise resolving to the statement description
|
|
33
|
-
*/
|
|
34
|
-
async describe(sql, queryOptions) {
|
|
35
|
-
const request = {
|
|
36
|
-
baton: this.baton,
|
|
37
|
-
requests: [{
|
|
38
|
-
type: "describe",
|
|
39
|
-
sql: sql
|
|
40
|
-
}]
|
|
41
|
-
};
|
|
42
|
-
let response;
|
|
43
|
-
try {
|
|
44
|
-
response = await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
|
|
45
|
-
}
|
|
46
|
-
catch (e) {
|
|
47
|
-
this.baton = null;
|
|
48
|
-
throw e;
|
|
49
|
-
}
|
|
50
|
-
this.baton = response.baton;
|
|
51
|
-
if (response.base_url) {
|
|
52
|
-
this.baseUrl = response.base_url;
|
|
53
|
-
}
|
|
54
|
-
// Check for errors in the response
|
|
55
|
-
if (response.results && response.results[0]) {
|
|
56
|
-
const result = response.results[0];
|
|
57
|
-
if (result.type === "error") {
|
|
58
|
-
throw new DatabaseError(result.error?.message || 'Describe execution failed', result.error?.code);
|
|
59
|
-
}
|
|
60
|
-
if (result.response?.type === "describe" && result.response.result) {
|
|
61
|
-
return result.response.result;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
throw new DatabaseError('Unexpected describe response');
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Execute a SQL statement and return all results.
|
|
68
|
-
*
|
|
69
|
-
* @param sql - The SQL statement to execute
|
|
70
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
71
|
-
* @param safeIntegers - Whether to return integers as BigInt
|
|
72
|
-
* @returns Promise resolving to the complete result set
|
|
73
|
-
*/
|
|
74
|
-
async execute(sql, args = [], safeIntegers = false, queryOptions) {
|
|
75
|
-
const { response, entries } = await this.executeRaw(sql, args, queryOptions);
|
|
76
|
-
const result = await this.processCursorEntries(entries, safeIntegers);
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Execute a SQL statement and return the raw response and entries.
|
|
81
|
-
*
|
|
82
|
-
* @param sql - The SQL statement to execute
|
|
83
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
84
|
-
* @returns Promise resolving to the raw response and cursor entries
|
|
85
|
-
*/
|
|
86
|
-
async executeRaw(sql, args = [], queryOptions) {
|
|
87
|
-
let positionalArgs = [];
|
|
88
|
-
let namedArgs = [];
|
|
89
|
-
if (Array.isArray(args)) {
|
|
90
|
-
positionalArgs = args.map(encodeValue);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
// Check if this is an object with numeric keys (for ?1, ?2 style parameters)
|
|
94
|
-
const keys = Object.keys(args);
|
|
95
|
-
const isNumericKeys = keys.length > 0 && keys.every(key => /^\d+$/.test(key));
|
|
96
|
-
if (isNumericKeys) {
|
|
97
|
-
// Convert numeric-keyed object to positional args
|
|
98
|
-
// Sort keys numerically to ensure correct order
|
|
99
|
-
const sortedKeys = keys.sort((a, b) => parseInt(a) - parseInt(b));
|
|
100
|
-
const maxIndex = parseInt(sortedKeys[sortedKeys.length - 1]);
|
|
101
|
-
// Create array with undefined for missing indices
|
|
102
|
-
positionalArgs = new Array(maxIndex);
|
|
103
|
-
for (const key of sortedKeys) {
|
|
104
|
-
const index = parseInt(key) - 1; // Convert to 0-based index
|
|
105
|
-
positionalArgs[index] = encodeValue(args[key]);
|
|
106
|
-
}
|
|
107
|
-
// Fill any undefined values with null
|
|
108
|
-
for (let i = 0; i < positionalArgs.length; i++) {
|
|
109
|
-
if (positionalArgs[i] === undefined) {
|
|
110
|
-
positionalArgs[i] = { type: 'null' };
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
// Convert object with named parameters to NamedArg array
|
|
116
|
-
namedArgs = Object.entries(args).map(([name, value]) => ({
|
|
117
|
-
name,
|
|
118
|
-
value: encodeValue(value)
|
|
119
|
-
}));
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
const request = {
|
|
123
|
-
baton: this.baton,
|
|
124
|
-
batch: {
|
|
125
|
-
steps: [{
|
|
126
|
-
stmt: {
|
|
127
|
-
sql,
|
|
128
|
-
args: positionalArgs,
|
|
129
|
-
named_args: namedArgs,
|
|
130
|
-
want_rows: true
|
|
131
|
-
}
|
|
132
|
-
}]
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
let result;
|
|
136
|
-
try {
|
|
137
|
-
result = await executeCursor(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
|
|
138
|
-
}
|
|
139
|
-
catch (e) {
|
|
140
|
-
this.baton = null;
|
|
141
|
-
throw e;
|
|
142
|
-
}
|
|
143
|
-
const { response, entries } = result;
|
|
144
|
-
this.baton = response.baton;
|
|
145
|
-
if (response.base_url) {
|
|
146
|
-
this.baseUrl = response.base_url;
|
|
147
|
-
}
|
|
148
|
-
return { response, entries };
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Process cursor entries into a structured result.
|
|
152
|
-
*
|
|
153
|
-
* @param entries - Async generator of cursor entries
|
|
154
|
-
* @returns Promise resolving to the processed result
|
|
155
|
-
*/
|
|
156
|
-
async processCursorEntries(entries, safeIntegers = false) {
|
|
157
|
-
let columns = [];
|
|
158
|
-
let columnTypes = [];
|
|
159
|
-
let rows = [];
|
|
160
|
-
let rowsAffected = 0;
|
|
161
|
-
let lastInsertRowid;
|
|
162
|
-
for await (const entry of entries) {
|
|
163
|
-
switch (entry.type) {
|
|
164
|
-
case 'step_begin':
|
|
165
|
-
if (entry.cols) {
|
|
166
|
-
columns = entry.cols.map(col => col.name);
|
|
167
|
-
columnTypes = entry.cols.map(col => col.decltype || '');
|
|
168
|
-
}
|
|
169
|
-
break;
|
|
170
|
-
case 'row':
|
|
171
|
-
if (entry.row) {
|
|
172
|
-
const decodedRow = entry.row.map(value => decodeValue(value, safeIntegers));
|
|
173
|
-
const rowObject = this.createRowObject(decodedRow, columns);
|
|
174
|
-
rows.push(rowObject);
|
|
175
|
-
}
|
|
176
|
-
break;
|
|
177
|
-
case 'step_end':
|
|
178
|
-
if (entry.affected_row_count !== undefined) {
|
|
179
|
-
rowsAffected = entry.affected_row_count;
|
|
180
|
-
}
|
|
181
|
-
if (entry.last_insert_rowid !== undefined && entry.last_insert_rowid !== null) {
|
|
182
|
-
lastInsertRowid = typeof entry.last_insert_rowid === 'number'
|
|
183
|
-
? entry.last_insert_rowid
|
|
184
|
-
: parseInt(entry.last_insert_rowid, 10);
|
|
185
|
-
}
|
|
186
|
-
break;
|
|
187
|
-
case 'step_error':
|
|
188
|
-
case 'error':
|
|
189
|
-
throw new DatabaseError(entry.error?.message || 'SQL execution failed', entry.error?.code);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
columns,
|
|
194
|
-
columnTypes,
|
|
195
|
-
rows,
|
|
196
|
-
rowsAffected,
|
|
197
|
-
lastInsertRowid
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Create a row object with both array and named property access.
|
|
202
|
-
*
|
|
203
|
-
* @param values - Array of column values
|
|
204
|
-
* @param columns - Array of column names
|
|
205
|
-
* @returns Row object with dual access patterns
|
|
206
|
-
*/
|
|
207
|
-
createRowObject(values, columns) {
|
|
208
|
-
const row = [...values];
|
|
209
|
-
// Add column name properties to the array as non-enumerable
|
|
210
|
-
// Only add valid identifier names to avoid conflicts
|
|
211
|
-
columns.forEach((column, index) => {
|
|
212
|
-
if (column && isValidIdentifier(column)) {
|
|
213
|
-
Object.defineProperty(row, column, {
|
|
214
|
-
value: values[index],
|
|
215
|
-
enumerable: false,
|
|
216
|
-
writable: false,
|
|
217
|
-
configurable: true
|
|
218
|
-
});
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
return row;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Execute multiple SQL statements in a batch.
|
|
225
|
-
*
|
|
226
|
-
* @param statements - Array of SQL statements to execute
|
|
227
|
-
* @returns Promise resolving to batch execution results
|
|
228
|
-
*/
|
|
229
|
-
async batch(statements, queryOptions) {
|
|
230
|
-
const request = {
|
|
231
|
-
baton: this.baton,
|
|
232
|
-
batch: {
|
|
233
|
-
steps: statements.map(sql => ({
|
|
234
|
-
stmt: {
|
|
235
|
-
sql,
|
|
236
|
-
args: [],
|
|
237
|
-
named_args: [],
|
|
238
|
-
want_rows: false
|
|
239
|
-
}
|
|
240
|
-
}))
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
let batchResult;
|
|
244
|
-
try {
|
|
245
|
-
batchResult = await executeCursor(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
|
|
246
|
-
}
|
|
247
|
-
catch (e) {
|
|
248
|
-
this.baton = null;
|
|
249
|
-
throw e;
|
|
250
|
-
}
|
|
251
|
-
const { response, entries } = batchResult;
|
|
252
|
-
this.baton = response.baton;
|
|
253
|
-
if (response.base_url) {
|
|
254
|
-
this.baseUrl = response.base_url;
|
|
255
|
-
}
|
|
256
|
-
let totalRowsAffected = 0;
|
|
257
|
-
let lastInsertRowid;
|
|
258
|
-
for await (const entry of entries) {
|
|
259
|
-
switch (entry.type) {
|
|
260
|
-
case 'step_end':
|
|
261
|
-
if (entry.affected_row_count !== undefined) {
|
|
262
|
-
totalRowsAffected += entry.affected_row_count;
|
|
263
|
-
}
|
|
264
|
-
if (entry.last_insert_rowid !== undefined && entry.last_insert_rowid !== null) {
|
|
265
|
-
lastInsertRowid = typeof entry.last_insert_rowid === 'number'
|
|
266
|
-
? entry.last_insert_rowid
|
|
267
|
-
: parseInt(entry.last_insert_rowid, 10);
|
|
268
|
-
}
|
|
269
|
-
break;
|
|
270
|
-
case 'step_error':
|
|
271
|
-
case 'error':
|
|
272
|
-
throw new DatabaseError(entry.error?.message || 'Batch execution failed', entry.error?.code);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
return {
|
|
276
|
-
rowsAffected: totalRowsAffected,
|
|
277
|
-
lastInsertRowid
|
|
278
|
-
};
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Execute a sequence of SQL statements separated by semicolons.
|
|
282
|
-
*
|
|
283
|
-
* @param sql - SQL string containing multiple statements separated by semicolons
|
|
284
|
-
* @returns Promise resolving when all statements are executed
|
|
285
|
-
*/
|
|
286
|
-
async sequence(sql, queryOptions) {
|
|
287
|
-
const request = {
|
|
288
|
-
baton: this.baton,
|
|
289
|
-
requests: [{
|
|
290
|
-
type: "sequence",
|
|
291
|
-
sql: sql
|
|
292
|
-
}]
|
|
293
|
-
};
|
|
294
|
-
let seqResponse;
|
|
295
|
-
try {
|
|
296
|
-
seqResponse = await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey, this.createAbortSignal(queryOptions));
|
|
297
|
-
}
|
|
298
|
-
catch (e) {
|
|
299
|
-
this.baton = null;
|
|
300
|
-
throw e;
|
|
301
|
-
}
|
|
302
|
-
this.baton = seqResponse.baton;
|
|
303
|
-
if (seqResponse.base_url) {
|
|
304
|
-
this.baseUrl = seqResponse.base_url;
|
|
305
|
-
}
|
|
306
|
-
// Check for errors in the response
|
|
307
|
-
if (seqResponse.results && seqResponse.results[0]) {
|
|
308
|
-
const result = seqResponse.results[0];
|
|
309
|
-
if (result.type === "error") {
|
|
310
|
-
throw new DatabaseError(result.error?.message || 'Sequence execution failed', result.error?.code);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Close the session.
|
|
316
|
-
*
|
|
317
|
-
* This sends a close request to the server to properly clean up the stream
|
|
318
|
-
* before resetting the local state.
|
|
319
|
-
*/
|
|
320
|
-
async close() {
|
|
321
|
-
// Only send close request if we have an active baton
|
|
322
|
-
if (this.baton) {
|
|
323
|
-
try {
|
|
324
|
-
const request = {
|
|
325
|
-
baton: this.baton,
|
|
326
|
-
requests: [{
|
|
327
|
-
type: "close"
|
|
328
|
-
}]
|
|
329
|
-
};
|
|
330
|
-
await executePipeline(this.baseUrl, this.config.authToken, request, this.config.remoteEncryptionKey);
|
|
331
|
-
}
|
|
332
|
-
catch {
|
|
333
|
-
// Ignore errors during close — the connection might already be closed
|
|
334
|
-
// or the baton may be stale after a timeout.
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
// Reset local state
|
|
338
|
-
this.baton = null;
|
|
339
|
-
this.baseUrl = '';
|
|
340
|
-
}
|
|
341
|
-
}
|
package/dist/statement.d.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import { type Column, type QueryOptions } from './protocol.js';
|
|
2
|
-
import { Session, type SessionConfig } from './session.js';
|
|
3
|
-
import { type AsyncLock } from './async-lock.js';
|
|
4
|
-
/**
|
|
5
|
-
* A prepared SQL statement that can be executed in multiple ways.
|
|
6
|
-
*
|
|
7
|
-
* Statements may either own a dedicated session or share a connection session to preserve transaction boundaries.
|
|
8
|
-
* Provides three execution modes:
|
|
9
|
-
* - `get(args?)`: Returns the first row or null
|
|
10
|
-
* - `all(args?)`: Returns all rows as an array
|
|
11
|
-
* - `iterate(args?)`: Returns an async iterator for streaming results
|
|
12
|
-
*/
|
|
13
|
-
export declare class Statement {
|
|
14
|
-
private session;
|
|
15
|
-
private sql;
|
|
16
|
-
private presentationMode;
|
|
17
|
-
private safeIntegerMode;
|
|
18
|
-
private columnMetadata;
|
|
19
|
-
private execLock?;
|
|
20
|
-
constructor(sessionConfig: SessionConfig, sql: string, columns?: Column[]);
|
|
21
|
-
/**
|
|
22
|
-
* Create a Statement that shares an existing session and serializes execution
|
|
23
|
-
* through the given lock. Used by Connection.prepare() so prepared statements
|
|
24
|
-
* participate in the connection's transaction scope.
|
|
25
|
-
*/
|
|
26
|
-
static fromSession(session: Session, sql: string, columns: Column[] | undefined, execLock: AsyncLock): Statement;
|
|
27
|
-
/**
|
|
28
|
-
* Whether the prepared statement returns data.
|
|
29
|
-
*
|
|
30
|
-
* This is `true` for SELECT queries and statements with RETURNING clause,
|
|
31
|
-
* and `false` for INSERT, UPDATE, DELETE statements without RETURNING.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* const stmt = await conn.prepare(sql);
|
|
36
|
-
* if (stmt.reader) {
|
|
37
|
-
* return stmt.all(args); // SELECT-like query
|
|
38
|
-
* } else {
|
|
39
|
-
* return stmt.run(args); // INSERT/UPDATE/DELETE
|
|
40
|
-
* }
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
get reader(): boolean;
|
|
44
|
-
/**
|
|
45
|
-
* Enable raw mode to return arrays instead of objects.
|
|
46
|
-
*
|
|
47
|
-
* @param raw Enable or disable raw mode. If you don't pass the parameter, raw mode is enabled.
|
|
48
|
-
* @returns This statement instance for chaining
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* ```typescript
|
|
52
|
-
* const stmt = client.prepare("SELECT * FROM users WHERE id = ?");
|
|
53
|
-
* const row = await stmt.raw().get([1]);
|
|
54
|
-
* console.log(row); // [1, "Alice", "alice@example.org"]
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
raw(raw?: boolean): Statement;
|
|
58
|
-
/**
|
|
59
|
-
* Enable pluck mode to return only the first column value from each row.
|
|
60
|
-
*
|
|
61
|
-
* @param pluck Enable or disable pluck mode. If you don't pass the parameter, pluck mode is enabled.
|
|
62
|
-
* @returns This statement instance for chaining
|
|
63
|
-
*
|
|
64
|
-
* @example
|
|
65
|
-
* ```typescript
|
|
66
|
-
* const stmt = client.prepare("SELECT id FROM users");
|
|
67
|
-
* const ids = await stmt.pluck().all();
|
|
68
|
-
* console.log(ids); // [1, 2, 3, ...]
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
|
-
pluck(pluck?: boolean): Statement;
|
|
72
|
-
/**
|
|
73
|
-
* Sets safe integers mode for this statement.
|
|
74
|
-
*
|
|
75
|
-
* @param toggle Whether to use safe integers. If you don't pass the parameter, safe integers mode is enabled.
|
|
76
|
-
* @returns This statement instance for chaining
|
|
77
|
-
*/
|
|
78
|
-
safeIntegers(toggle?: boolean): Statement;
|
|
79
|
-
/**
|
|
80
|
-
* Get column information for this statement.
|
|
81
|
-
*
|
|
82
|
-
* @returns Array of column metadata objects matching the native bindings format
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const stmt = await client.prepare("SELECT id, name, email FROM users");
|
|
87
|
-
* const columns = stmt.columns();
|
|
88
|
-
* console.log(columns); // [{ name: 'id', type: 'INTEGER', column: null, database: null, table: null }, ...]
|
|
89
|
-
* ```
|
|
90
|
-
*/
|
|
91
|
-
columns(): any[];
|
|
92
|
-
private withLock;
|
|
93
|
-
/**
|
|
94
|
-
* Executes the prepared statement.
|
|
95
|
-
*
|
|
96
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
97
|
-
* @returns Promise resolving to the result of the statement
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* ```typescript
|
|
101
|
-
* const stmt = client.prepare("INSERT INTO users (name, email) VALUES (?, ?)");
|
|
102
|
-
* const result = await stmt.run(['John Doe', 'john.doe@example.com']);
|
|
103
|
-
* console.log(`Inserted user with ID ${result.lastInsertRowid}`);
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
run(args?: any, queryOptions?: QueryOptions): Promise<any>;
|
|
107
|
-
/**
|
|
108
|
-
* Execute the statement and return the first row.
|
|
109
|
-
*
|
|
110
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
111
|
-
* @returns Promise resolving to the first row or undefined if no results
|
|
112
|
-
*
|
|
113
|
-
* @example
|
|
114
|
-
* ```typescript
|
|
115
|
-
* const stmt = client.prepare("SELECT * FROM users WHERE id = ?");
|
|
116
|
-
* const user = await stmt.get([123]);
|
|
117
|
-
* if (user) {
|
|
118
|
-
* console.log(user.name);
|
|
119
|
-
* }
|
|
120
|
-
* ```
|
|
121
|
-
*/
|
|
122
|
-
get(args?: any, queryOptions?: QueryOptions): Promise<any>;
|
|
123
|
-
/**
|
|
124
|
-
* Execute the statement and return all rows.
|
|
125
|
-
*
|
|
126
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
127
|
-
* @returns Promise resolving to an array of all result rows
|
|
128
|
-
*
|
|
129
|
-
* @example
|
|
130
|
-
* ```typescript
|
|
131
|
-
* const stmt = client.prepare("SELECT * FROM users WHERE active = ?");
|
|
132
|
-
* const activeUsers = await stmt.all([true]);
|
|
133
|
-
* console.log(`Found ${activeUsers.length} active users`);
|
|
134
|
-
* ```
|
|
135
|
-
*/
|
|
136
|
-
all(args?: any, queryOptions?: QueryOptions): Promise<any[]>;
|
|
137
|
-
/**
|
|
138
|
-
* Execute the statement and return an async iterator for streaming results.
|
|
139
|
-
*
|
|
140
|
-
* This method provides memory-efficient processing of large result sets
|
|
141
|
-
* by streaming rows one at a time instead of loading everything into memory.
|
|
142
|
-
*
|
|
143
|
-
* @param args - Optional array of parameter values or object with named parameters
|
|
144
|
-
* @returns AsyncGenerator that yields individual rows
|
|
145
|
-
*
|
|
146
|
-
* @example
|
|
147
|
-
* ```typescript
|
|
148
|
-
* const stmt = client.prepare("SELECT * FROM large_table WHERE category = ?");
|
|
149
|
-
* for await (const row of stmt.iterate(['electronics'])) {
|
|
150
|
-
* // Process each row individually
|
|
151
|
-
* console.log(row.id, row.name);
|
|
152
|
-
* }
|
|
153
|
-
* ```
|
|
154
|
-
*/
|
|
155
|
-
iterate(args?: any, queryOptions?: QueryOptions): AsyncGenerator<any>;
|
|
156
|
-
/**
|
|
157
|
-
* Normalize arguments to handle both single values and arrays.
|
|
158
|
-
* Matches the behavior of the native bindings.
|
|
159
|
-
*/
|
|
160
|
-
private normalizeArgs;
|
|
161
|
-
}
|