@ladybugdb/core-darwin-x64 0.22.0-dev.20261012 → 0.22.0-dev.20261018
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/lbug.d.ts +13 -3
- package/lbugjs.node +0 -0
- package/package.json +1 -1
- package/query_result.js +47 -11
package/lbug.d.ts
CHANGED
|
@@ -394,7 +394,9 @@ export class QueryResult {
|
|
|
394
394
|
getNumTuples(): number;
|
|
395
395
|
|
|
396
396
|
/**
|
|
397
|
-
* Get the next row.
|
|
397
|
+
* Get the next row. This method is asynchronous and must be awaited
|
|
398
|
+
* (`await result.getNext()`); in synchronous code, use `getNextSync()`
|
|
399
|
+
* instead.
|
|
398
400
|
* @returns Promise that resolves to the next row or null if no more rows
|
|
399
401
|
*/
|
|
400
402
|
getNext(): Promise<Record<string, LbugValue> | null>;
|
|
@@ -419,6 +421,12 @@ export class QueryResult {
|
|
|
419
421
|
|
|
420
422
|
/**
|
|
421
423
|
* Get all rows of the query result.
|
|
424
|
+
*
|
|
425
|
+
* WARNING: this method is asynchronous and must be awaited
|
|
426
|
+
* (`await result.getAll()`). Using it without `await` yields a pending
|
|
427
|
+
* Promise (which `JSON.stringify` renders as `{}`), not the rows;
|
|
428
|
+
* serializing that Promise throws an error pointing here. In synchronous
|
|
429
|
+
* code, use `getAllSync()` instead.
|
|
422
430
|
* @returns Promise that resolves to all rows
|
|
423
431
|
*/
|
|
424
432
|
getAll(): Promise<Record<string, LbugValue>[]>;
|
|
@@ -440,7 +448,8 @@ export class QueryResult {
|
|
|
440
448
|
): void;
|
|
441
449
|
|
|
442
450
|
/**
|
|
443
|
-
* Get the column data types.
|
|
451
|
+
* Get the column data types. This method is asynchronous and must be
|
|
452
|
+
* awaited; in synchronous code, use `getColumnDataTypesSync()` instead.
|
|
444
453
|
* @returns Promise that resolves to array of data type strings
|
|
445
454
|
*/
|
|
446
455
|
getColumnDataTypes(): Promise<string[]>;
|
|
@@ -452,7 +461,8 @@ export class QueryResult {
|
|
|
452
461
|
getColumnDataTypesSync(): string[];
|
|
453
462
|
|
|
454
463
|
/**
|
|
455
|
-
* Get the column names.
|
|
464
|
+
* Get the column names. This method is asynchronous and must be awaited;
|
|
465
|
+
* in synchronous code, use `getColumnNamesSync()` instead.
|
|
456
466
|
* @returns Promise that resolves to array of column names
|
|
457
467
|
*/
|
|
458
468
|
getColumnNames(): Promise<string[]>;
|
package/lbugjs.node
CHANGED
|
Binary file
|
package/package.json
CHANGED
package/query_result.js
CHANGED
|
@@ -2,6 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
const assert = require("assert");
|
|
4
4
|
|
|
5
|
+
const GET_ALL_AWAIT_MESSAGE =
|
|
6
|
+
"QueryResult.getAll() returns a Promise and must be awaited " +
|
|
7
|
+
"(`await result.getAll()`). In synchronous code, use `result.getAllSync()` instead. " +
|
|
8
|
+
"Serializing the un-awaited Promise (e.g. via JSON.stringify, which renders it as '{}') " +
|
|
9
|
+
"is almost certainly a bug.";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Promise returned by QueryResult.getAll(). Behaves exactly like a native
|
|
13
|
+
* Promise, except that serializing it (e.g. via JSON.stringify, which renders
|
|
14
|
+
* a plain pending Promise as '{}') throws a descriptive error instead of
|
|
15
|
+
* silently producing '{}' that looks like an empty result.
|
|
16
|
+
*/
|
|
17
|
+
class GetAllPromise extends Promise {
|
|
18
|
+
toJSON() {
|
|
19
|
+
throw new Error(GET_ALL_AWAIT_MESSAGE);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
class QueryResult {
|
|
6
24
|
/**
|
|
7
25
|
* Internal constructor. Use `Connection.query` or `Connection.execute`
|
|
@@ -51,7 +69,9 @@ class QueryResult {
|
|
|
51
69
|
}
|
|
52
70
|
|
|
53
71
|
/**
|
|
54
|
-
* Get the next row of the query result.
|
|
72
|
+
* Get the next row of the query result. This method is asynchronous and must
|
|
73
|
+
* be awaited (`await result.getNext()`); in synchronous code, use
|
|
74
|
+
* `getNextSync()` instead.
|
|
55
75
|
* @returns {Promise<Object>} a promise that resolves to the next row of the query result. The promise is rejected if there is an error.
|
|
56
76
|
*/
|
|
57
77
|
getNext() {
|
|
@@ -98,16 +118,26 @@ class QueryResult {
|
|
|
98
118
|
|
|
99
119
|
/**
|
|
100
120
|
* Get all rows of the query result.
|
|
121
|
+
*
|
|
122
|
+
* WARNING: this method is asynchronous and returns a Promise — it must be
|
|
123
|
+
* awaited (`await result.getAll()`). Using it without `await` yields a
|
|
124
|
+
* pending Promise (which `JSON.stringify` renders as `{}`), not the rows;
|
|
125
|
+
* serializing that Promise throws an error pointing here. In synchronous
|
|
126
|
+
* code, use `getAllSync()` instead.
|
|
101
127
|
* @returns {Promise<Array<Object>>} a promise that resolves to all rows of the query result. The promise is rejected if there is an error.
|
|
102
128
|
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
129
|
+
getAll() {
|
|
130
|
+
return new GetAllPromise((resolve, reject) => {
|
|
131
|
+
(async () => {
|
|
132
|
+
this._checkClosed();
|
|
133
|
+
this._queryResult.resetIterator();
|
|
134
|
+
const result = [];
|
|
135
|
+
while (this.hasNext()) {
|
|
136
|
+
result.push(await this.getNext());
|
|
137
|
+
}
|
|
138
|
+
return result;
|
|
139
|
+
})().then(resolve, reject);
|
|
140
|
+
});
|
|
111
141
|
}
|
|
112
142
|
|
|
113
143
|
/**
|
|
@@ -141,7 +171,9 @@ class QueryResult {
|
|
|
141
171
|
}
|
|
142
172
|
|
|
143
173
|
/**
|
|
144
|
-
* Get the data types of the columns of the query result.
|
|
174
|
+
* Get the data types of the columns of the query result. This method is
|
|
175
|
+
* asynchronous and must be awaited; in synchronous code, use
|
|
176
|
+
* `getColumnDataTypesSync()` instead.
|
|
145
177
|
* @returns {Promise<Array<String>>} a promise that resolves to the data types of the columns of the query result. The promise is rejected if there is an error.
|
|
146
178
|
*/
|
|
147
179
|
getColumnDataTypes() {
|
|
@@ -166,7 +198,9 @@ class QueryResult {
|
|
|
166
198
|
}
|
|
167
199
|
|
|
168
200
|
/**
|
|
169
|
-
* Get the names of the columns of the query result.
|
|
201
|
+
* Get the names of the columns of the query result. This method is
|
|
202
|
+
* asynchronous and must be awaited; in synchronous code, use
|
|
203
|
+
* `getColumnNamesSync()` instead.
|
|
170
204
|
* @returns {Promise<Array<String>>} a promise that resolves to the names of the columns of the query result. The promise is rejected if there is an error.
|
|
171
205
|
*/
|
|
172
206
|
getColumnNames() {
|
|
@@ -192,6 +226,8 @@ class QueryResult {
|
|
|
192
226
|
|
|
193
227
|
/**
|
|
194
228
|
* Get the query summary (compiling and execution time) of the query result.
|
|
229
|
+
* This method is asynchronous and must be awaited; in synchronous code, use
|
|
230
|
+
* `getQuerySummarySync()` instead.
|
|
195
231
|
* @returns {Promise<Object>} a promise that resolves to the query summary of the query result. The promise is rejected if there is an error.
|
|
196
232
|
*/
|
|
197
233
|
getQuerySummary() {
|