expo-sqlite 13.1.2 → 13.2.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/CHANGELOG.md +6 -0
- package/android/build.gradle +2 -2
- package/build/next/SQLiteStatement.d.ts +19 -0
- package/build/next/SQLiteStatement.d.ts.map +1 -1
- package/build/next/SQLiteStatement.js +72 -33
- package/build/next/SQLiteStatement.js.map +1 -1
- package/package.json +2 -2
- package/src/next/SQLiteStatement.ts +143 -45
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,12 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 13.2.0 — 2023-12-21
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Added `SQLiteStatement.executeForRawResultAsync()` in `expo-sqlite/next` API which returns array based raw values than key-value based row value. ([#26073](https://github.com/expo/expo/pull/26073) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
13
19
|
## 13.1.2 — 2023-12-21
|
|
14
20
|
|
|
15
21
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -4,7 +4,7 @@ apply plugin: 'maven-publish'
|
|
|
4
4
|
apply plugin: 'de.undercouch.download'
|
|
5
5
|
|
|
6
6
|
group = 'host.exp.exponent'
|
|
7
|
-
version = '13.
|
|
7
|
+
version = '13.2.0'
|
|
8
8
|
|
|
9
9
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
10
|
if (expoModulesCorePlugin.exists()) {
|
|
@@ -106,7 +106,7 @@ android {
|
|
|
106
106
|
namespace "expo.modules.sqlite"
|
|
107
107
|
defaultConfig {
|
|
108
108
|
versionCode 18
|
|
109
|
-
versionName "13.
|
|
109
|
+
versionName "13.2.0"
|
|
110
110
|
|
|
111
111
|
externalNativeBuild {
|
|
112
112
|
cmake {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NativeDatabase } from './NativeDatabase';
|
|
2
2
|
import { SQLiteBindParams, SQLiteBindValue, NativeStatement, SQLiteVariadicBindParams, type SQLiteRunResult } from './NativeStatement';
|
|
3
3
|
export { SQLiteBindParams, SQLiteBindValue, SQLiteRunResult, SQLiteVariadicBindParams };
|
|
4
|
+
type ValuesOf<T extends object> = T[keyof T][];
|
|
4
5
|
/**
|
|
5
6
|
* A prepared statement returned by [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource) or [`SQLiteDatabase.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.
|
|
6
7
|
*/
|
|
@@ -17,6 +18,15 @@ export declare class SQLiteStatement {
|
|
|
17
18
|
* @hidden
|
|
18
19
|
*/
|
|
19
20
|
executeAsync<T>(...params: SQLiteVariadicBindParams): Promise<SQLiteExecuteAsyncResult<T>>;
|
|
21
|
+
/**
|
|
22
|
+
* Similar to [`executeAsync()`](#executeasyncparams) but returns the raw value array result instead of the row objects.
|
|
23
|
+
* @hidden Advanced use only.
|
|
24
|
+
*/
|
|
25
|
+
executeForRawResultAsync<T extends object>(params: SQLiteBindParams): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>>;
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
*/
|
|
29
|
+
executeForRawResultAsync<T extends object>(...params: SQLiteVariadicBindParams): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>>;
|
|
20
30
|
/**
|
|
21
31
|
* Get the column names of the prepared statement.
|
|
22
32
|
*/
|
|
@@ -38,6 +48,15 @@ export declare class SQLiteStatement {
|
|
|
38
48
|
* @hidden
|
|
39
49
|
*/
|
|
40
50
|
executeSync<T>(...params: SQLiteVariadicBindParams): SQLiteExecuteSyncResult<T>;
|
|
51
|
+
/**
|
|
52
|
+
* Similar to [`executeSync()`](#executesyncparams) but returns the raw value array result instead of the row objects.
|
|
53
|
+
* @hidden Advanced use only.
|
|
54
|
+
*/
|
|
55
|
+
executeForRawResultSync<T extends object>(params: SQLiteBindParams): SQLiteExecuteSyncResult<ValuesOf<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* @hidden
|
|
58
|
+
*/
|
|
59
|
+
executeForRawResultSync<T extends object>(...params: SQLiteVariadicBindParams): SQLiteExecuteSyncResult<ValuesOf<T>>;
|
|
41
60
|
/**
|
|
42
61
|
* Get the column names of the prepared statement.
|
|
43
62
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLiteStatement.d.ts","sourceRoot":"","sources":["../../src/next/SQLiteStatement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,wBAAwB,
|
|
1
|
+
{"version":3,"file":"SQLiteStatement.d.ts","sourceRoot":"","sources":["../../src/next/SQLiteStatement.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,wBAAwB,EAIxB,KAAK,eAAe,EACrB,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,eAAe,EAAE,wBAAwB,EAAE,CAAC;AAExF,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;AAE/C;;GAEG;AACH,qBAAa,eAAe;IAExB,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe;gBADf,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,eAAe;IAKnD;;;OAGG;IACI,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC;IACtF;;OAEG;IACI,YAAY,CAAC,CAAC,EAAE,GAAG,MAAM,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AC,eAAe,EAAE,MAAM,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,aAAa,IAAI,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;IAEnC;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC;IAE5B;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,WAAW,uBAAuB,CAAC,CAAC,CAAE,SAAQ,gBAAgB,CAAC,CAAC,CAAC;IACrE;;OAEG;IACH,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IAEjC;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,YAAY,IAAI,CAAC,GAAG,IAAI,CAAC;IAEzB;;OAEG;IACH,UAAU,IAAI,CAAC,EAAE,CAAC;IAElB;;OAEG;IACH,SAAS,IAAI,IAAI,CAAC;CACnB"}
|
|
@@ -11,7 +11,19 @@ export class SQLiteStatement {
|
|
|
11
11
|
}
|
|
12
12
|
async executeAsync(...params) {
|
|
13
13
|
const { lastInsertRowId, changes, firstRowValues } = await this.nativeStatement.runAsync(this.nativeDatabase, ...normalizeParams(...params));
|
|
14
|
-
return createSQLiteExecuteAsyncResult(this.nativeDatabase, this.nativeStatement,
|
|
14
|
+
return createSQLiteExecuteAsyncResult(this.nativeDatabase, this.nativeStatement, firstRowValues, {
|
|
15
|
+
rawResult: false,
|
|
16
|
+
lastInsertRowId,
|
|
17
|
+
changes,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async executeForRawResultAsync(...params) {
|
|
21
|
+
const { lastInsertRowId, changes, firstRowValues } = await this.nativeStatement.runAsync(this.nativeDatabase, ...normalizeParams(...params));
|
|
22
|
+
return createSQLiteExecuteAsyncResult(this.nativeDatabase, this.nativeStatement, firstRowValues, {
|
|
23
|
+
rawResult: true,
|
|
24
|
+
lastInsertRowId,
|
|
25
|
+
changes,
|
|
26
|
+
});
|
|
15
27
|
}
|
|
16
28
|
/**
|
|
17
29
|
* Get the column names of the prepared statement.
|
|
@@ -30,7 +42,19 @@ export class SQLiteStatement {
|
|
|
30
42
|
}
|
|
31
43
|
executeSync(...params) {
|
|
32
44
|
const { lastInsertRowId, changes, firstRowValues } = this.nativeStatement.runSync(this.nativeDatabase, ...normalizeParams(...params));
|
|
33
|
-
return createSQLiteExecuteSyncResult(this.nativeDatabase, this.nativeStatement,
|
|
45
|
+
return createSQLiteExecuteSyncResult(this.nativeDatabase, this.nativeStatement, firstRowValues, {
|
|
46
|
+
rawResult: false,
|
|
47
|
+
lastInsertRowId,
|
|
48
|
+
changes,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
executeForRawResultSync(...params) {
|
|
52
|
+
const { lastInsertRowId, changes, firstRowValues } = this.nativeStatement.runSync(this.nativeDatabase, ...normalizeParams(...params));
|
|
53
|
+
return createSQLiteExecuteSyncResult(this.nativeDatabase, this.nativeStatement, firstRowValues, {
|
|
54
|
+
rawResult: true,
|
|
55
|
+
lastInsertRowId,
|
|
56
|
+
changes,
|
|
57
|
+
});
|
|
34
58
|
}
|
|
35
59
|
/**
|
|
36
60
|
* Get the column names of the prepared statement.
|
|
@@ -48,24 +72,23 @@ export class SQLiteStatement {
|
|
|
48
72
|
this.nativeStatement.finalizeSync(this.nativeDatabase);
|
|
49
73
|
}
|
|
50
74
|
}
|
|
51
|
-
//#region Internals for SQLiteExecuteAsyncResult and SQLiteExecuteSyncResult
|
|
52
75
|
/**
|
|
53
76
|
* Create the `SQLiteExecuteAsyncResult` instance.
|
|
54
77
|
*
|
|
55
78
|
* NOTE: Since Hermes does not support the `Symbol.asyncIterator` feature, we have to use an AsyncGenerator to implement the `AsyncIterableIterator` interface.
|
|
56
79
|
* This is done by `Object.defineProperties` to add the properties to the AsyncGenerator.
|
|
57
80
|
*/
|
|
58
|
-
async function createSQLiteExecuteAsyncResult(database, statement,
|
|
59
|
-
const instance = new SQLiteExecuteAsyncResultImpl(database, statement,
|
|
81
|
+
async function createSQLiteExecuteAsyncResult(database, statement, firstRowValues, options) {
|
|
82
|
+
const instance = new SQLiteExecuteAsyncResultImpl(database, statement, firstRowValues, options);
|
|
60
83
|
const generator = instance.generatorAsync();
|
|
61
84
|
Object.defineProperties(generator, {
|
|
62
85
|
lastInsertRowId: {
|
|
63
|
-
value: lastInsertRowId,
|
|
86
|
+
value: options.lastInsertRowId,
|
|
64
87
|
enumerable: true,
|
|
65
88
|
writable: false,
|
|
66
89
|
configurable: true,
|
|
67
90
|
},
|
|
68
|
-
changes: { value: changes, enumerable: true, writable: false, configurable: true },
|
|
91
|
+
changes: { value: options.changes, enumerable: true, writable: false, configurable: true },
|
|
69
92
|
getFirstAsync: {
|
|
70
93
|
value: instance.getFirstAsync.bind(instance),
|
|
71
94
|
enumerable: true,
|
|
@@ -90,17 +113,17 @@ async function createSQLiteExecuteAsyncResult(database, statement, lastInsertRow
|
|
|
90
113
|
/**
|
|
91
114
|
* Create the `SQLiteExecuteSyncResult` instance.
|
|
92
115
|
*/
|
|
93
|
-
function createSQLiteExecuteSyncResult(database, statement,
|
|
94
|
-
const instance = new SQLiteExecuteSyncResultImpl(database, statement,
|
|
116
|
+
function createSQLiteExecuteSyncResult(database, statement, firstRowValues, options) {
|
|
117
|
+
const instance = new SQLiteExecuteSyncResultImpl(database, statement, firstRowValues, options);
|
|
95
118
|
const generator = instance.generatorSync();
|
|
96
119
|
Object.defineProperties(generator, {
|
|
97
120
|
lastInsertRowId: {
|
|
98
|
-
value: lastInsertRowId,
|
|
121
|
+
value: options.lastInsertRowId,
|
|
99
122
|
enumerable: true,
|
|
100
123
|
writable: false,
|
|
101
124
|
configurable: true,
|
|
102
125
|
},
|
|
103
|
-
changes: { value: changes, enumerable: true, writable: false, configurable: true },
|
|
126
|
+
changes: { value: options.changes, enumerable: true, writable: false, configurable: true },
|
|
104
127
|
getFirstSync: {
|
|
105
128
|
value: instance.getFirstSync.bind(instance),
|
|
106
129
|
enumerable: true,
|
|
@@ -125,17 +148,15 @@ function createSQLiteExecuteSyncResult(database, statement, lastInsertRowId, cha
|
|
|
125
148
|
class SQLiteExecuteAsyncResultImpl {
|
|
126
149
|
database;
|
|
127
150
|
statement;
|
|
128
|
-
lastInsertRowId;
|
|
129
|
-
changes;
|
|
130
151
|
firstRowValues;
|
|
152
|
+
options;
|
|
131
153
|
columnNames = null;
|
|
132
154
|
isStepCalled = false;
|
|
133
|
-
constructor(database, statement,
|
|
155
|
+
constructor(database, statement, firstRowValues, options) {
|
|
134
156
|
this.database = database;
|
|
135
157
|
this.statement = statement;
|
|
136
|
-
this.lastInsertRowId = lastInsertRowId;
|
|
137
|
-
this.changes = changes;
|
|
138
158
|
this.firstRowValues = firstRowValues;
|
|
159
|
+
this.options = options;
|
|
139
160
|
}
|
|
140
161
|
async getFirstAsync() {
|
|
141
162
|
if (this.isStepCalled) {
|
|
@@ -145,10 +166,12 @@ class SQLiteExecuteAsyncResultImpl {
|
|
|
145
166
|
const columnNames = await this.getColumnNamesAsync();
|
|
146
167
|
const firstRowValues = this.popFirstRowValues();
|
|
147
168
|
if (firstRowValues != null) {
|
|
148
|
-
return
|
|
169
|
+
return composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
149
170
|
}
|
|
150
171
|
const firstRow = await this.statement.stepAsync(this.database);
|
|
151
|
-
return firstRow != null
|
|
172
|
+
return firstRow != null
|
|
173
|
+
? composeRowIfNeeded(this.options.rawResult, columnNames, firstRow)
|
|
174
|
+
: null;
|
|
152
175
|
}
|
|
153
176
|
async getAllAsync() {
|
|
154
177
|
if (this.isStepCalled) {
|
|
@@ -159,22 +182,25 @@ class SQLiteExecuteAsyncResultImpl {
|
|
|
159
182
|
const allRows = await this.statement.getAllAsync(this.database);
|
|
160
183
|
const firstRowValues = this.popFirstRowValues();
|
|
161
184
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
162
|
-
return
|
|
185
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, [
|
|
186
|
+
firstRowValues,
|
|
187
|
+
...allRows,
|
|
188
|
+
]);
|
|
163
189
|
}
|
|
164
|
-
return
|
|
190
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, allRows);
|
|
165
191
|
}
|
|
166
192
|
async *generatorAsync() {
|
|
167
193
|
this.isStepCalled = true;
|
|
168
194
|
const columnNames = await this.getColumnNamesAsync();
|
|
169
195
|
const firstRowValues = this.popFirstRowValues();
|
|
170
196
|
if (firstRowValues != null) {
|
|
171
|
-
yield
|
|
197
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
172
198
|
}
|
|
173
199
|
let result;
|
|
174
200
|
do {
|
|
175
201
|
result = await this.statement.stepAsync(this.database);
|
|
176
202
|
if (result != null) {
|
|
177
|
-
yield
|
|
203
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, result);
|
|
178
204
|
}
|
|
179
205
|
} while (result != null);
|
|
180
206
|
}
|
|
@@ -201,17 +227,15 @@ class SQLiteExecuteAsyncResultImpl {
|
|
|
201
227
|
class SQLiteExecuteSyncResultImpl {
|
|
202
228
|
database;
|
|
203
229
|
statement;
|
|
204
|
-
lastInsertRowId;
|
|
205
|
-
changes;
|
|
206
230
|
firstRowValues;
|
|
231
|
+
options;
|
|
207
232
|
columnNames = null;
|
|
208
233
|
isStepCalled = false;
|
|
209
|
-
constructor(database, statement,
|
|
234
|
+
constructor(database, statement, firstRowValues, options) {
|
|
210
235
|
this.database = database;
|
|
211
236
|
this.statement = statement;
|
|
212
|
-
this.lastInsertRowId = lastInsertRowId;
|
|
213
|
-
this.changes = changes;
|
|
214
237
|
this.firstRowValues = firstRowValues;
|
|
238
|
+
this.options = options;
|
|
215
239
|
}
|
|
216
240
|
getFirstSync() {
|
|
217
241
|
if (this.isStepCalled) {
|
|
@@ -220,10 +244,12 @@ class SQLiteExecuteSyncResultImpl {
|
|
|
220
244
|
const columnNames = this.getColumnNamesSync();
|
|
221
245
|
const firstRowValues = this.popFirstRowValues();
|
|
222
246
|
if (firstRowValues != null) {
|
|
223
|
-
return
|
|
247
|
+
return composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
224
248
|
}
|
|
225
249
|
const firstRow = this.statement.stepSync(this.database);
|
|
226
|
-
return firstRow != null
|
|
250
|
+
return firstRow != null
|
|
251
|
+
? composeRowIfNeeded(this.options.rawResult, columnNames, firstRow)
|
|
252
|
+
: null;
|
|
227
253
|
}
|
|
228
254
|
getAllSync() {
|
|
229
255
|
if (this.isStepCalled) {
|
|
@@ -233,21 +259,24 @@ class SQLiteExecuteSyncResultImpl {
|
|
|
233
259
|
const allRows = this.statement.getAllSync(this.database);
|
|
234
260
|
const firstRowValues = this.popFirstRowValues();
|
|
235
261
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
236
|
-
return
|
|
262
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, [
|
|
263
|
+
firstRowValues,
|
|
264
|
+
...allRows,
|
|
265
|
+
]);
|
|
237
266
|
}
|
|
238
|
-
return
|
|
267
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, allRows);
|
|
239
268
|
}
|
|
240
269
|
*generatorSync() {
|
|
241
270
|
const columnNames = this.getColumnNamesSync();
|
|
242
271
|
const firstRowValues = this.popFirstRowValues();
|
|
243
272
|
if (firstRowValues != null) {
|
|
244
|
-
yield
|
|
273
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
245
274
|
}
|
|
246
275
|
let result;
|
|
247
276
|
do {
|
|
248
277
|
result = this.statement.stepSync(this.database);
|
|
249
278
|
if (result != null) {
|
|
250
|
-
yield
|
|
279
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, result);
|
|
251
280
|
}
|
|
252
281
|
} while (result != null);
|
|
253
282
|
}
|
|
@@ -271,5 +300,15 @@ class SQLiteExecuteSyncResultImpl {
|
|
|
271
300
|
return this.columnNames;
|
|
272
301
|
}
|
|
273
302
|
}
|
|
303
|
+
function composeRowIfNeeded(rawResult, columnNames, columnValues) {
|
|
304
|
+
return rawResult
|
|
305
|
+
? columnValues // T would be a ValuesOf<> from caller
|
|
306
|
+
: composeRow(columnNames, columnValues);
|
|
307
|
+
}
|
|
308
|
+
function composeRowsIfNeeded(rawResult, columnNames, columnValuesList) {
|
|
309
|
+
return rawResult
|
|
310
|
+
? columnValuesList // T[] would be a ValuesOf<>[] from caller
|
|
311
|
+
: composeRows(columnNames, columnValuesList);
|
|
312
|
+
}
|
|
274
313
|
//#endregion
|
|
275
314
|
//# sourceMappingURL=SQLiteStatement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SQLiteStatement.js","sourceRoot":"","sources":["../../src/next/SQLiteStatement.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAIxE;;GAEG;AACH,MAAM,OAAO,eAAe;IAEP;IACA;IAFnB,YACmB,cAA8B,EAC9B,eAAgC;QADhC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAaG,KAAK,CAAC,YAAY,CAAI,GAAG,MAAiB;QAC/C,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CACtF,IAAI,CAAC,cAAc,EACnB,GAAG,eAAe,CAAC,GAAG,MAAM,CAAC,CAC9B,CAAC;QACF,OAAO,8BAA8B,CACnC,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,eAAe,EACpB,eAAe,EACf,OAAO,EACP,cAAc,CACf,CAAC;IACJ,CAAC;IAED;;OAEG;IACI,mBAAmB;QACxB,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAmB,E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AG;YACD,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;YAChD,IAAI,MAAM,IAAI,IAAI,EAAE;gBAClB,MAAM,UAAU,CAAI,WAAW,EAAE,MAAM,CAAC,CAAC;aAC1C;SACF,QAAQ,MAAM,IAAI,IAAI,EAAE;IAC3B,CAAC;IAED,SAAS;QACP,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC1B,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,iBAAiB;QACvB,IAAI,IAAI,CAAC,cAAc,IAAI,IAAI,EAAE;YAC/B,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;YAC3C,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,OAAO,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC;SAC1D;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,kBAAkB;QACxB,IAAI,IAAI,CAAC,WAAW,IAAI,IAAI,EAAE;YAC5B,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC;SACxD;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAED,YAAY","sourcesContent":["import { NativeDatabase } from './NativeDatabase';\nimport {\n SQLiteBindParams,\n SQLiteBindValue,\n NativeStatement,\n SQLiteVariadicBindParams,\n type SQLiteAnyDatabase,\n type SQLiteRunResult,\n SQLiteColumnValues,\n} from './NativeStatement';\nimport { composeRow, composeRows, normalizeParams } from './paramUtils';\n\nexport { SQLiteBindParams, SQLiteBindValue, SQLiteRunResult, SQLiteVariadicBindParams };\n\n/**\n * A prepared statement returned by [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource) or [`SQLiteDatabase.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.\n */\nexport class SQLiteStatement {\n constructor(\n private readonly nativeDatabase: NativeDatabase,\n private readonly nativeStatement: NativeStatement\n ) {}\n\n //#region Asynchronous API\n\n /**\n * Run the prepared statement and return the [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) instance.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public executeAsync<T>(params: SQLiteBindParams): Promise<SQLiteExecuteAsyncResult<T>>;\n /**\n * @hidden\n */\n public executeAsync<T>(...params: SQLiteVariadicBindParams): Promise<SQLiteExecuteAsyncResult<T>>;\n public async executeAsync<T>(...params: unknown[]): Promise<SQLiteExecuteAsyncResult<T>> {\n const { lastInsertRowId, changes, firstRowValues } = await this.nativeStatement.runAsync(\n this.nativeDatabase,\n ...normalizeParams(...params)\n );\n return createSQLiteExecuteAsyncResult<T>(\n this.nativeDatabase,\n this.nativeStatement,\n lastInsertRowId,\n changes,\n firstRowValues\n );\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesAsync(): Promise<string[]> {\n return this.nativeStatement.getColumnNamesAsync();\n }\n\n /**\n * Finalize the prepared statement. This will call the [`sqlite3_finalize()`](https://www.sqlite.org/c3ref/finalize.html) C function under the hood.\n *\n * Attempting to access a finalized statement will result in an error.\n * > **Note:** While expo-sqlite will automatically finalize any orphaned prepared statements upon closing the database, it is considered best practice to manually finalize prepared statements as soon as they are no longer needed. This helps to prevent resource leaks. You can use the `try...finally` statement to ensure that prepared statements are finalized even if an error occurs.\n */\n public async finalizeAsync(): Promise<void> {\n await this.nativeStatement.finalizeAsync(this.nativeDatabase);\n }\n\n //#endregion\n\n //#region Synchronous API\n\n /**\n * Run the prepared statement and return the [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) instance.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public executeSync<T>(params: SQLiteBindParams): SQLiteExecuteSyncResult<T>;\n /**\n * @hidden\n */\n public executeSync<T>(...params: SQLiteVariadicBindParams): SQLiteExecuteSyncResult<T>;\n public executeSync<T>(...params: unknown[]): SQLiteExecuteSyncResult<T> {\n const { lastInsertRowId, changes, firstRowValues } = this.nativeStatement.runSync(\n this.nativeDatabase,\n ...normalizeParams(...params)\n );\n return createSQLiteExecuteSyncResult<T>(\n this.nativeDatabase,\n this.nativeStatement,\n lastInsertRowId,\n changes,\n firstRowValues\n );\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesSync(): string[] {\n return this.nativeStatement.getColumnNamesSync();\n }\n\n /**\n * Finalize the prepared statement. This will call the [`sqlite3_finalize()`](https://www.sqlite.org/c3ref/finalize.html) C function under the hood.\n *\n * Attempting to access a finalized statement will result in an error.\n * > **Note:** While expo-sqlite will automatically finalize any orphaned prepared statements upon closing the database, it is considered best practice to manually finalize prepared statements as soon as they are no longer needed. This helps to prevent resource leaks. You can use the `try...finally` statement to ensure that prepared statements are finalized even if an error occurs.\n */\n public finalizeSync(): void {\n this.nativeStatement.finalizeSync(this.nativeDatabase);\n }\n\n //#endregion\n}\n\n/**\n * A result returned by [`SQLiteStatement.executeAsync()`](#executeasyncparams).\n *\n * @example\n * The result includes the [`lastInsertRowId`](https://www.sqlite.org/c3ref/last_insert_rowid.html) and [`changes`](https://www.sqlite.org/c3ref/changes.html) properties. You can get the information from the write operations.\n * ```ts\n * const statement = await db.prepareAsync('INSERT INTO test (value) VALUES (?)');\n * try {\n * const result = await statement.executeAsync(101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * } finally {\n * await statement.finalizeAsync();\n * }\n * ```\n *\n * @example\n * The result implements the [`AsyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) interface, so you can use it in `for await...of` loops.\n * ```ts\n * const statement = await db.prepareAsync('SELECT value FROM test WHERE value > ?');\n * try {\n * const result = await statement.executeAsync<{ value: number }>(100);\n * for await (const row of result) {\n * console.log('row value:', row.value);\n * }\n * } finally {\n * await statement.finalizeAsync();\n * }\n * ```\n *\n * @example\n * If your write operations also return values, you can mix all of them together.\n * ```ts\n * const statement = await db.prepareAsync('INSERT INTO test (name, value) VALUES (?, ?) RETURNING name');\n * try {\n * const result = await statement.executeAsync<{ name: string }>('John Doe', 101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * for await (const row of result) {\n * console.log('name:', row.name);\n * }\n * } finally {\n * await statement.finalizeAsync();\n * }\n * ```\n */\nexport interface SQLiteExecuteAsyncResult<T> extends AsyncIterableIterator<T> {\n /**\n * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.\n */\n readonly lastInsertRowId: number;\n\n /**\n * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.\n */\n readonly changes: number;\n\n /**\n * Get the first row of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetAsync()`](#resetasync). Otherwise, an error will be thrown.\n */\n getFirstAsync(): Promise<T | null>;\n\n /**\n * Get all rows of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetAsync()`](#resetasync). Otherwise, an error will be thrown.\n */\n getAllAsync(): Promise<T[]>;\n\n /**\n * Reset the prepared statement cursor. This will call the [`sqlite3_reset()`](https://www.sqlite.org/c3ref/reset.html) C function under the hood.\n */\n resetAsync(): Promise<void>;\n}\n\n/**\n * A result returned by [`SQLiteStatement.executeSync()`](#executesyncparams).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n\n * @example\n * The result includes the [`lastInsertRowId`](https://www.sqlite.org/c3ref/last_insert_rowid.html) and [`changes`](https://www.sqlite.org/c3ref/changes.html) properties. You can get the information from the write operations.\n * ```ts\n * const statement = db.prepareSync('INSERT INTO test (value) VALUES (?)');\n * try {\n * const result = statement.executeSync(101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * } finally {\n * statement.finalizeSync();\n * }\n * ```\n *\n * @example\n * The result implements the [`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) interface, so you can use it in `for...of` loops.\n * ```ts\n * const statement = db.prepareSync('SELECT value FROM test WHERE value > ?');\n * try {\n * const result = statement.executeSync<{ value: number }>(100);\n * for (const row of result) {\n * console.log('row value:', row.value);\n * }\n * } finally {\n * statement.finalizeSync();\n * }\n * ```\n *\n * @example\n * If your write operations also return values, you can mix all of them together.\n * ```ts\n * const statement = db.prepareSync('INSERT INTO test (name, value) VALUES (?, ?) RETURNING name');\n * try {\n * const result = statement.executeSync<{ name: string }>('John Doe', 101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * for (const row of result) {\n * console.log('name:', row.name);\n * }\n * } finally {\n * statement.finalizeSync();\n * }\n * ```\n */\nexport interface SQLiteExecuteSyncResult<T> extends IterableIterator<T> {\n /**\n * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.\n */\n readonly lastInsertRowId: number;\n\n /**\n * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.\n */\n readonly changes: number;\n\n /**\n * Get the first row of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetSync()`](#resetsync). Otherwise, an error will be thrown.\n */\n getFirstSync(): T | null;\n\n /**\n * Get all rows of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetSync()`](#resetsync). Otherwise, an error will be thrown.\n */\n getAllSync(): T[];\n\n /**\n * Reset the prepared statement cursor. This will call the [`sqlite3_reset()`](https://www.sqlite.org/c3ref/reset.html) C function under the hood.\n */\n resetSync(): void;\n}\n\n//#region Internals for SQLiteExecuteAsyncResult and SQLiteExecuteSyncResult\n\n/**\n * Create the `SQLiteExecuteAsyncResult` instance.\n *\n * NOTE: Since Hermes does not support the `Symbol.asyncIterator` feature, we have to use an AsyncGenerator to implement the `AsyncIterableIterator` interface.\n * This is done by `Object.defineProperties` to add the properties to the AsyncGenerator.\n */\nasync function createSQLiteExecuteAsyncResult<T>(\n database: SQLiteAnyDatabase,\n statement: NativeStatement,\n lastInsertRowId: number,\n changes: number,\n firstRowValues: SQLiteColumnValues | null\n): Promise<SQLiteExecuteAsyncResult<T>> {\n const instance = new SQLiteExecuteAsyncResultImpl<T>(\n database,\n statement,\n lastInsertRowId,\n changes,\n firstRowValues\n );\n const generator = instance.generatorAsync();\n Object.defineProperties(generator, {\n lastInsertRowId: {\n value: lastInsertRowId,\n enumerable: true,\n writable: false,\n configurable: true,\n },\n changes: { value: changes, enumerable: true, writable: false, configurable: true },\n getFirstAsync: {\n value: instance.getFirstAsync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n getAllAsync: {\n value: instance.getAllAsync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n resetAsync: {\n value: instance.resetAsync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n });\n\n return generator as SQLiteExecuteAsyncResult<T>;\n}\n\n/**\n * Create the `SQLiteExecuteSyncResult` instance.\n */\nfunction createSQLiteExecuteSyncResult<T>(\n database: SQLiteAnyDatabase,\n statement: NativeStatement,\n lastInsertRowId: number,\n changes: number,\n firstRowValues: SQLiteColumnValues | null\n): SQLiteExecuteSyncResult<T> {\n const instance = new SQLiteExecuteSyncResultImpl<T>(\n database,\n statement,\n lastInsertRowId,\n changes,\n firstRowValues\n );\n const generator = instance.generatorSync();\n Object.defineProperties(generator, {\n lastInsertRowId: {\n value: lastInsertRowId,\n enumerable: true,\n writable: false,\n configurable: true,\n },\n changes: { value: changes, enumerable: true, writable: false, configurable: true },\n getFirstSync: {\n value: instance.getFirstSync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n getAllSync: {\n value: instance.getAllSync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n resetSync: {\n value: instance.resetSync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n });\n\n return generator as SQLiteExecuteSyncResult<T>;\n}\n\nclass SQLiteExecuteAsyncResultImpl<T> {\n private columnNames: string[] | null = null;\n private isStepCalled = false;\n\n constructor(\n private readonly database: SQLiteAnyDatabase,\n private readonly statement: NativeStatement,\n public readonly lastInsertRowId: number,\n public readonly changes: number,\n private firstRowValues: SQLiteColumnValues | null\n ) {}\n\n async getFirstAsync(): Promise<T | null> {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve the first row without being reset. Invoke `resetAsync()` to reset the cursor first if you want to retrieve the first row.'\n );\n }\n this.isStepCalled = true;\n const columnNames = await this.getColumnNamesAsync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n return composeRow<T>(columnNames, firstRowValues);\n }\n const firstRow = await this.statement.stepAsync(this.database);\n return firstRow != null ? composeRow<T>(columnNames, firstRow) : null;\n }\n\n async getAllAsync(): Promise<T[]> {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve all rows without being reset. Invoke `resetAsync()` to reset the cursor first if you want to retrieve all rows.'\n );\n }\n this.isStepCalled = true;\n const columnNames = await this.getColumnNamesAsync();\n const allRows = await this.statement.getAllAsync(this.database);\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null && firstRowValues.length > 0) {\n return composeRows<T>(columnNames, [firstRowValues, ...allRows]);\n }\n return composeRows<T>(columnNames, allRows);\n }\n\n async *generatorAsync(): AsyncIterableIterator<T> {\n this.isStepCalled = true;\n const columnNames = await this.getColumnNamesAsync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n yield composeRow<T>(columnNames, firstRowValues);\n }\n\n let result;\n do {\n result = await this.statement.stepAsync(this.database);\n if (result != null) {\n yield composeRow<T>(columnNames, result);\n }\n } while (result != null);\n }\n\n resetAsync(): Promise<void> {\n const result = this.statement.resetAsync(this.database);\n this.isStepCalled = false;\n return result;\n }\n\n private popFirstRowValues(): SQLiteColumnValues | null {\n if (this.firstRowValues != null) {\n const firstRowValues = this.firstRowValues;\n this.firstRowValues = null;\n return firstRowValues.length > 0 ? firstRowValues : null;\n }\n return null;\n }\n\n private async getColumnNamesAsync(): Promise<string[]> {\n if (this.columnNames == null) {\n this.columnNames = await this.statement.getColumnNamesAsync();\n }\n return this.columnNames;\n }\n}\n\nclass SQLiteExecuteSyncResultImpl<T> {\n private columnNames: string[] | null = null;\n private isStepCalled = false;\n\n constructor(\n private readonly database: SQLiteAnyDatabase,\n private readonly statement: NativeStatement,\n public readonly lastInsertRowId: number,\n public readonly changes: number,\n private firstRowValues: SQLiteColumnValues | null\n ) {}\n\n getFirstSync(): T | null {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve the first row without being reset. Invoke `resetSync()` to reset the cursor first if you want to retrieve the first row.'\n );\n }\n const columnNames = this.getColumnNamesSync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n return composeRow<T>(columnNames, firstRowValues);\n }\n const firstRow = this.statement.stepSync(this.database);\n return firstRow != null ? composeRow<T>(columnNames, firstRow) : null;\n }\n\n getAllSync(): T[] {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve all rows without being reset. Invoke `resetSync()` to reset the cursor first if you want to retrieve all rows.'\n );\n }\n const columnNames = this.getColumnNamesSync();\n const allRows = this.statement.getAllSync(this.database);\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null && firstRowValues.length > 0) {\n return composeRows<T>(columnNames, [firstRowValues, ...allRows]);\n }\n return composeRows<T>(columnNames, allRows);\n }\n\n *generatorSync(): IterableIterator<T> {\n const columnNames = this.getColumnNamesSync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n yield composeRow<T>(columnNames, firstRowValues);\n }\n let result;\n do {\n result = this.statement.stepSync(this.database);\n if (result != null) {\n yield composeRow<T>(columnNames, result);\n }\n } while (result != null);\n }\n\n resetSync(): void {\n const result = this.statement.resetSync(this.database);\n this.isStepCalled = false;\n return result;\n }\n\n private popFirstRowValues(): SQLiteColumnValues | null {\n if (this.firstRowValues != null) {\n const firstRowValues = this.firstRowValues;\n this.firstRowValues = null;\n return firstRowValues.length > 0 ? firstRowValues : null;\n }\n return null;\n }\n\n private getColumnNamesSync(): string[] {\n if (this.columnNames == null) {\n this.columnNames = this.statement.getColumnNamesSync();\n }\n return this.columnNames;\n }\n}\n\n//#endregion\n"]}
|
|
1
|
+
{"version":3,"file":"SQLiteStatement.js","sourceRoot":"","sources":["../../src/next/SQLiteStatement.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAMxE;;GAEG;AACH,MAAM,OAAO,eAAe;IAEP;IACA;IAFnB,YACmB,cAA8B,EAC9B,eAAgC;QADhC,mBAAc,GAAd,cAAc,CAAgB;QAC9B,oBAAe,GAAf,eAAe,CAAiB;IAChD,CAAC;IAaG,KAAK,CAAC,YAAY,CAAI,GAAG,MAAiB;QAC/C,MAAM,EAAE,eAAe,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,CACtF,IAAI,CAAC,cAAc,EACnB,GAAG,eAAe,CAAC,GAAG,MAAM,CAAC,CAC9B,CAAC;QACF,OAAO,8BAA8B,CACnC,IAAI,CAAC,cAAc,EACnB,IAAI,CAAC,eAAe,EACpB,cA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O,SAAS;QACd,CAAC,CAAE,gBAAwB,CAAC,0CAA0C;QACtE,CAAC,CAAC,WAAW,CAAI,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACpD,CAAC;AAED,YAAY","sourcesContent":["import { NativeDatabase } from './NativeDatabase';\nimport {\n SQLiteBindParams,\n SQLiteBindValue,\n NativeStatement,\n SQLiteVariadicBindParams,\n type SQLiteAnyDatabase,\n type SQLiteColumnNames,\n type SQLiteColumnValues,\n type SQLiteRunResult,\n} from './NativeStatement';\nimport { composeRow, composeRows, normalizeParams } from './paramUtils';\n\nexport { SQLiteBindParams, SQLiteBindValue, SQLiteRunResult, SQLiteVariadicBindParams };\n\ntype ValuesOf<T extends object> = T[keyof T][];\n\n/**\n * A prepared statement returned by [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource) or [`SQLiteDatabase.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.\n */\nexport class SQLiteStatement {\n constructor(\n private readonly nativeDatabase: NativeDatabase,\n private readonly nativeStatement: NativeStatement\n ) {}\n\n //#region Asynchronous API\n\n /**\n * Run the prepared statement and return the [`SQLiteExecuteAsyncResult`](#sqliteexecuteasyncresult) instance.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public executeAsync<T>(params: SQLiteBindParams): Promise<SQLiteExecuteAsyncResult<T>>;\n /**\n * @hidden\n */\n public executeAsync<T>(...params: SQLiteVariadicBindParams): Promise<SQLiteExecuteAsyncResult<T>>;\n public async executeAsync<T>(...params: unknown[]): Promise<SQLiteExecuteAsyncResult<T>> {\n const { lastInsertRowId, changes, firstRowValues } = await this.nativeStatement.runAsync(\n this.nativeDatabase,\n ...normalizeParams(...params)\n );\n return createSQLiteExecuteAsyncResult<T>(\n this.nativeDatabase,\n this.nativeStatement,\n firstRowValues,\n {\n rawResult: false,\n lastInsertRowId,\n changes,\n }\n );\n }\n\n /**\n * Similar to [`executeAsync()`](#executeasyncparams) but returns the raw value array result instead of the row objects.\n * @hidden Advanced use only.\n */\n public executeForRawResultAsync<T extends object>(\n params: SQLiteBindParams\n ): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>>;\n /**\n * @hidden\n */\n public executeForRawResultAsync<T extends object>(\n ...params: SQLiteVariadicBindParams\n ): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>>;\n public async executeForRawResultAsync<T extends object>(\n ...params: unknown[]\n ): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>> {\n const { lastInsertRowId, changes, firstRowValues } = await this.nativeStatement.runAsync(\n this.nativeDatabase,\n ...normalizeParams(...params)\n );\n return createSQLiteExecuteAsyncResult<ValuesOf<T>>(\n this.nativeDatabase,\n this.nativeStatement,\n firstRowValues,\n {\n rawResult: true,\n lastInsertRowId,\n changes,\n }\n );\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesAsync(): Promise<string[]> {\n return this.nativeStatement.getColumnNamesAsync();\n }\n\n /**\n * Finalize the prepared statement. This will call the [`sqlite3_finalize()`](https://www.sqlite.org/c3ref/finalize.html) C function under the hood.\n *\n * Attempting to access a finalized statement will result in an error.\n * > **Note:** While expo-sqlite will automatically finalize any orphaned prepared statements upon closing the database, it is considered best practice to manually finalize prepared statements as soon as they are no longer needed. This helps to prevent resource leaks. You can use the `try...finally` statement to ensure that prepared statements are finalized even if an error occurs.\n */\n public async finalizeAsync(): Promise<void> {\n await this.nativeStatement.finalizeAsync(this.nativeDatabase);\n }\n\n //#endregion\n\n //#region Synchronous API\n\n /**\n * Run the prepared statement and return the [`SQLiteExecuteSyncResult`](#sqliteexecutesyncresult) instance.\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n * @param params The parameters to bind to the prepared statement. You can pass values in array, object, or variadic arguments. See [`SQLiteBindValue`](#sqlitebindvalue) for more information about binding values.\n */\n public executeSync<T>(params: SQLiteBindParams): SQLiteExecuteSyncResult<T>;\n /**\n * @hidden\n */\n public executeSync<T>(...params: SQLiteVariadicBindParams): SQLiteExecuteSyncResult<T>;\n public executeSync<T>(...params: unknown[]): SQLiteExecuteSyncResult<T> {\n const { lastInsertRowId, changes, firstRowValues } = this.nativeStatement.runSync(\n this.nativeDatabase,\n ...normalizeParams(...params)\n );\n return createSQLiteExecuteSyncResult<T>(\n this.nativeDatabase,\n this.nativeStatement,\n firstRowValues,\n {\n rawResult: false,\n lastInsertRowId,\n changes,\n }\n );\n }\n\n /**\n * Similar to [`executeSync()`](#executesyncparams) but returns the raw value array result instead of the row objects.\n * @hidden Advanced use only.\n */\n public executeForRawResultSync<T extends object>(\n params: SQLiteBindParams\n ): SQLiteExecuteSyncResult<ValuesOf<T>>;\n /**\n * @hidden\n */\n public executeForRawResultSync<T extends object>(\n ...params: SQLiteVariadicBindParams\n ): SQLiteExecuteSyncResult<ValuesOf<T>>;\n public executeForRawResultSync<T extends object>(\n ...params: unknown[]\n ): SQLiteExecuteSyncResult<ValuesOf<T>> {\n const { lastInsertRowId, changes, firstRowValues } = this.nativeStatement.runSync(\n this.nativeDatabase,\n ...normalizeParams(...params)\n );\n return createSQLiteExecuteSyncResult<ValuesOf<T>>(\n this.nativeDatabase,\n this.nativeStatement,\n firstRowValues,\n {\n rawResult: true,\n lastInsertRowId,\n changes,\n }\n );\n }\n\n /**\n * Get the column names of the prepared statement.\n */\n public getColumnNamesSync(): string[] {\n return this.nativeStatement.getColumnNamesSync();\n }\n\n /**\n * Finalize the prepared statement. This will call the [`sqlite3_finalize()`](https://www.sqlite.org/c3ref/finalize.html) C function under the hood.\n *\n * Attempting to access a finalized statement will result in an error.\n * > **Note:** While expo-sqlite will automatically finalize any orphaned prepared statements upon closing the database, it is considered best practice to manually finalize prepared statements as soon as they are no longer needed. This helps to prevent resource leaks. You can use the `try...finally` statement to ensure that prepared statements are finalized even if an error occurs.\n */\n public finalizeSync(): void {\n this.nativeStatement.finalizeSync(this.nativeDatabase);\n }\n\n //#endregion\n}\n\n/**\n * A result returned by [`SQLiteStatement.executeAsync()`](#executeasyncparams).\n *\n * @example\n * The result includes the [`lastInsertRowId`](https://www.sqlite.org/c3ref/last_insert_rowid.html) and [`changes`](https://www.sqlite.org/c3ref/changes.html) properties. You can get the information from the write operations.\n * ```ts\n * const statement = await db.prepareAsync('INSERT INTO test (value) VALUES (?)');\n * try {\n * const result = await statement.executeAsync(101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * } finally {\n * await statement.finalizeAsync();\n * }\n * ```\n *\n * @example\n * The result implements the [`AsyncIterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/asyncIterator) interface, so you can use it in `for await...of` loops.\n * ```ts\n * const statement = await db.prepareAsync('SELECT value FROM test WHERE value > ?');\n * try {\n * const result = await statement.executeAsync<{ value: number }>(100);\n * for await (const row of result) {\n * console.log('row value:', row.value);\n * }\n * } finally {\n * await statement.finalizeAsync();\n * }\n * ```\n *\n * @example\n * If your write operations also return values, you can mix all of them together.\n * ```ts\n * const statement = await db.prepareAsync('INSERT INTO test (name, value) VALUES (?, ?) RETURNING name');\n * try {\n * const result = await statement.executeAsync<{ name: string }>('John Doe', 101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * for await (const row of result) {\n * console.log('name:', row.name);\n * }\n * } finally {\n * await statement.finalizeAsync();\n * }\n * ```\n */\nexport interface SQLiteExecuteAsyncResult<T> extends AsyncIterableIterator<T> {\n /**\n * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.\n */\n readonly lastInsertRowId: number;\n\n /**\n * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.\n */\n readonly changes: number;\n\n /**\n * Get the first row of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetAsync()`](#resetasync). Otherwise, an error will be thrown.\n */\n getFirstAsync(): Promise<T | null>;\n\n /**\n * Get all rows of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetAsync()`](#resetasync). Otherwise, an error will be thrown.\n */\n getAllAsync(): Promise<T[]>;\n\n /**\n * Reset the prepared statement cursor. This will call the [`sqlite3_reset()`](https://www.sqlite.org/c3ref/reset.html) C function under the hood.\n */\n resetAsync(): Promise<void>;\n}\n\n/**\n * A result returned by [`SQLiteStatement.executeSync()`](#executesyncparams).\n * > **Note:** Running heavy tasks with this function can block the JavaScript thread and affect performance.\n\n * @example\n * The result includes the [`lastInsertRowId`](https://www.sqlite.org/c3ref/last_insert_rowid.html) and [`changes`](https://www.sqlite.org/c3ref/changes.html) properties. You can get the information from the write operations.\n * ```ts\n * const statement = db.prepareSync('INSERT INTO test (value) VALUES (?)');\n * try {\n * const result = statement.executeSync(101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * } finally {\n * statement.finalizeSync();\n * }\n * ```\n *\n * @example\n * The result implements the [`Iterator`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Iterator) interface, so you can use it in `for...of` loops.\n * ```ts\n * const statement = db.prepareSync('SELECT value FROM test WHERE value > ?');\n * try {\n * const result = statement.executeSync<{ value: number }>(100);\n * for (const row of result) {\n * console.log('row value:', row.value);\n * }\n * } finally {\n * statement.finalizeSync();\n * }\n * ```\n *\n * @example\n * If your write operations also return values, you can mix all of them together.\n * ```ts\n * const statement = db.prepareSync('INSERT INTO test (name, value) VALUES (?, ?) RETURNING name');\n * try {\n * const result = statement.executeSync<{ name: string }>('John Doe', 101);\n * console.log('lastInsertRowId:', result.lastInsertRowId);\n * console.log('changes:', result.changes);\n * for (const row of result) {\n * console.log('name:', row.name);\n * }\n * } finally {\n * statement.finalizeSync();\n * }\n * ```\n */\nexport interface SQLiteExecuteSyncResult<T> extends IterableIterator<T> {\n /**\n * The last inserted row ID. Returned from the [`sqlite3_last_insert_rowid()`](https://www.sqlite.org/c3ref/last_insert_rowid.html) function.\n */\n readonly lastInsertRowId: number;\n\n /**\n * The number of rows affected. Returned from the [`sqlite3_changes()`](https://www.sqlite.org/c3ref/changes.html) function.\n */\n readonly changes: number;\n\n /**\n * Get the first row of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetSync()`](#resetsync). Otherwise, an error will be thrown.\n */\n getFirstSync(): T | null;\n\n /**\n * Get all rows of the result set. This requires the SQLite cursor to be in its initial state. If you have already retrieved rows from the result set, you need to reset the cursor first by calling [`resetSync()`](#resetsync). Otherwise, an error will be thrown.\n */\n getAllSync(): T[];\n\n /**\n * Reset the prepared statement cursor. This will call the [`sqlite3_reset()`](https://www.sqlite.org/c3ref/reset.html) C function under the hood.\n */\n resetSync(): void;\n}\n\n//#region Internals for SQLiteExecuteAsyncResult and SQLiteExecuteSyncResult\n\ninterface SQLiteExecuteResultOptions {\n rawResult: boolean;\n lastInsertRowId: number;\n changes: number;\n}\n\n/**\n * Create the `SQLiteExecuteAsyncResult` instance.\n *\n * NOTE: Since Hermes does not support the `Symbol.asyncIterator` feature, we have to use an AsyncGenerator to implement the `AsyncIterableIterator` interface.\n * This is done by `Object.defineProperties` to add the properties to the AsyncGenerator.\n */\nasync function createSQLiteExecuteAsyncResult<T>(\n database: SQLiteAnyDatabase,\n statement: NativeStatement,\n firstRowValues: SQLiteColumnValues | null,\n options: SQLiteExecuteResultOptions\n): Promise<SQLiteExecuteAsyncResult<T>> {\n const instance = new SQLiteExecuteAsyncResultImpl<T>(\n database,\n statement,\n firstRowValues,\n options\n );\n const generator = instance.generatorAsync();\n Object.defineProperties(generator, {\n lastInsertRowId: {\n value: options.lastInsertRowId,\n enumerable: true,\n writable: false,\n configurable: true,\n },\n changes: { value: options.changes, enumerable: true, writable: false, configurable: true },\n getFirstAsync: {\n value: instance.getFirstAsync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n getAllAsync: {\n value: instance.getAllAsync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n resetAsync: {\n value: instance.resetAsync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n });\n\n return generator as SQLiteExecuteAsyncResult<T>;\n}\n\n/**\n * Create the `SQLiteExecuteSyncResult` instance.\n */\nfunction createSQLiteExecuteSyncResult<T>(\n database: SQLiteAnyDatabase,\n statement: NativeStatement,\n firstRowValues: SQLiteColumnValues | null,\n options: SQLiteExecuteResultOptions\n): SQLiteExecuteSyncResult<T> {\n const instance = new SQLiteExecuteSyncResultImpl<T>(database, statement, firstRowValues, options);\n const generator = instance.generatorSync();\n Object.defineProperties(generator, {\n lastInsertRowId: {\n value: options.lastInsertRowId,\n enumerable: true,\n writable: false,\n configurable: true,\n },\n changes: { value: options.changes, enumerable: true, writable: false, configurable: true },\n getFirstSync: {\n value: instance.getFirstSync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n getAllSync: {\n value: instance.getAllSync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n resetSync: {\n value: instance.resetSync.bind(instance),\n enumerable: true,\n writable: false,\n configurable: true,\n },\n });\n\n return generator as SQLiteExecuteSyncResult<T>;\n}\n\nclass SQLiteExecuteAsyncResultImpl<T> {\n private columnNames: string[] | null = null;\n private isStepCalled = false;\n\n constructor(\n private readonly database: SQLiteAnyDatabase,\n private readonly statement: NativeStatement,\n private firstRowValues: SQLiteColumnValues | null,\n public readonly options: SQLiteExecuteResultOptions\n ) {}\n\n async getFirstAsync(): Promise<T | null> {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve the first row without being reset. Invoke `resetAsync()` to reset the cursor first if you want to retrieve the first row.'\n );\n }\n this.isStepCalled = true;\n const columnNames = await this.getColumnNamesAsync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n return composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);\n }\n const firstRow = await this.statement.stepAsync(this.database);\n return firstRow != null\n ? composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRow)\n : null;\n }\n\n async getAllAsync(): Promise<T[]> {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve all rows without being reset. Invoke `resetAsync()` to reset the cursor first if you want to retrieve all rows.'\n );\n }\n this.isStepCalled = true;\n const columnNames = await this.getColumnNamesAsync();\n const allRows = await this.statement.getAllAsync(this.database);\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null && firstRowValues.length > 0) {\n return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, [\n firstRowValues,\n ...allRows,\n ]);\n }\n return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, allRows);\n }\n\n async *generatorAsync(): AsyncIterableIterator<T> {\n this.isStepCalled = true;\n const columnNames = await this.getColumnNamesAsync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);\n }\n\n let result;\n do {\n result = await this.statement.stepAsync(this.database);\n if (result != null) {\n yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, result);\n }\n } while (result != null);\n }\n\n resetAsync(): Promise<void> {\n const result = this.statement.resetAsync(this.database);\n this.isStepCalled = false;\n return result;\n }\n\n private popFirstRowValues(): SQLiteColumnValues | null {\n if (this.firstRowValues != null) {\n const firstRowValues = this.firstRowValues;\n this.firstRowValues = null;\n return firstRowValues.length > 0 ? firstRowValues : null;\n }\n return null;\n }\n\n private async getColumnNamesAsync(): Promise<string[]> {\n if (this.columnNames == null) {\n this.columnNames = await this.statement.getColumnNamesAsync();\n }\n return this.columnNames;\n }\n}\n\nclass SQLiteExecuteSyncResultImpl<T> {\n private columnNames: string[] | null = null;\n private isStepCalled = false;\n\n constructor(\n private readonly database: SQLiteAnyDatabase,\n private readonly statement: NativeStatement,\n private firstRowValues: SQLiteColumnValues | null,\n public readonly options: SQLiteExecuteResultOptions\n ) {}\n\n getFirstSync(): T | null {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve the first row without being reset. Invoke `resetSync()` to reset the cursor first if you want to retrieve the first row.'\n );\n }\n const columnNames = this.getColumnNamesSync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n return composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);\n }\n const firstRow = this.statement.stepSync(this.database);\n return firstRow != null\n ? composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRow)\n : null;\n }\n\n getAllSync(): T[] {\n if (this.isStepCalled) {\n throw new Error(\n 'The SQLite cursor has been shifted and is unable to retrieve all rows without being reset. Invoke `resetSync()` to reset the cursor first if you want to retrieve all rows.'\n );\n }\n const columnNames = this.getColumnNamesSync();\n const allRows = this.statement.getAllSync(this.database);\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null && firstRowValues.length > 0) {\n return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, [\n firstRowValues,\n ...allRows,\n ]);\n }\n return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, allRows);\n }\n\n *generatorSync(): IterableIterator<T> {\n const columnNames = this.getColumnNamesSync();\n const firstRowValues = this.popFirstRowValues();\n if (firstRowValues != null) {\n yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);\n }\n let result;\n do {\n result = this.statement.stepSync(this.database);\n if (result != null) {\n yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, result);\n }\n } while (result != null);\n }\n\n resetSync(): void {\n const result = this.statement.resetSync(this.database);\n this.isStepCalled = false;\n return result;\n }\n\n private popFirstRowValues(): SQLiteColumnValues | null {\n if (this.firstRowValues != null) {\n const firstRowValues = this.firstRowValues;\n this.firstRowValues = null;\n return firstRowValues.length > 0 ? firstRowValues : null;\n }\n return null;\n }\n\n private getColumnNamesSync(): string[] {\n if (this.columnNames == null) {\n this.columnNames = this.statement.getColumnNamesSync();\n }\n return this.columnNames;\n }\n}\n\nfunction composeRowIfNeeded<T>(\n rawResult: boolean,\n columnNames: SQLiteColumnNames,\n columnValues: SQLiteColumnValues\n): T {\n return rawResult\n ? (columnValues as T) // T would be a ValuesOf<> from caller\n : composeRow<T>(columnNames, columnValues);\n}\n\nfunction composeRowsIfNeeded<T>(\n rawResult: boolean,\n columnNames: SQLiteColumnNames,\n columnValuesList: SQLiteColumnValues[]\n): T[] {\n return rawResult\n ? (columnValuesList as T[]) // T[] would be a ValuesOf<>[] from caller\n : composeRows<T>(columnNames, columnValuesList);\n}\n\n//#endregion\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-sqlite",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.2.0",
|
|
4
4
|
"description": "Provides access to a database that can be queried through a WebSQL-like API (https://www.w3.org/TR/webdatabase/). The database is persisted across restarts of your app.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"expo": "*"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "e95fa8d71746a7daf15f88462d137ef367d8acb7"
|
|
51
51
|
}
|
|
@@ -5,13 +5,16 @@ import {
|
|
|
5
5
|
NativeStatement,
|
|
6
6
|
SQLiteVariadicBindParams,
|
|
7
7
|
type SQLiteAnyDatabase,
|
|
8
|
+
type SQLiteColumnNames,
|
|
9
|
+
type SQLiteColumnValues,
|
|
8
10
|
type SQLiteRunResult,
|
|
9
|
-
SQLiteColumnValues,
|
|
10
11
|
} from './NativeStatement';
|
|
11
12
|
import { composeRow, composeRows, normalizeParams } from './paramUtils';
|
|
12
13
|
|
|
13
14
|
export { SQLiteBindParams, SQLiteBindValue, SQLiteRunResult, SQLiteVariadicBindParams };
|
|
14
15
|
|
|
16
|
+
type ValuesOf<T extends object> = T[keyof T][];
|
|
17
|
+
|
|
15
18
|
/**
|
|
16
19
|
* A prepared statement returned by [`SQLiteDatabase.prepareAsync()`](#prepareasyncsource) or [`SQLiteDatabase.prepareSync()`](#preparesyncsource) that can be binded with parameters and executed.
|
|
17
20
|
*/
|
|
@@ -40,9 +43,44 @@ export class SQLiteStatement {
|
|
|
40
43
|
return createSQLiteExecuteAsyncResult<T>(
|
|
41
44
|
this.nativeDatabase,
|
|
42
45
|
this.nativeStatement,
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
firstRowValues,
|
|
47
|
+
{
|
|
48
|
+
rawResult: false,
|
|
49
|
+
lastInsertRowId,
|
|
50
|
+
changes,
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Similar to [`executeAsync()`](#executeasyncparams) but returns the raw value array result instead of the row objects.
|
|
57
|
+
* @hidden Advanced use only.
|
|
58
|
+
*/
|
|
59
|
+
public executeForRawResultAsync<T extends object>(
|
|
60
|
+
params: SQLiteBindParams
|
|
61
|
+
): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>>;
|
|
62
|
+
/**
|
|
63
|
+
* @hidden
|
|
64
|
+
*/
|
|
65
|
+
public executeForRawResultAsync<T extends object>(
|
|
66
|
+
...params: SQLiteVariadicBindParams
|
|
67
|
+
): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>>;
|
|
68
|
+
public async executeForRawResultAsync<T extends object>(
|
|
69
|
+
...params: unknown[]
|
|
70
|
+
): Promise<SQLiteExecuteAsyncResult<ValuesOf<T>>> {
|
|
71
|
+
const { lastInsertRowId, changes, firstRowValues } = await this.nativeStatement.runAsync(
|
|
72
|
+
this.nativeDatabase,
|
|
73
|
+
...normalizeParams(...params)
|
|
74
|
+
);
|
|
75
|
+
return createSQLiteExecuteAsyncResult<ValuesOf<T>>(
|
|
76
|
+
this.nativeDatabase,
|
|
77
|
+
this.nativeStatement,
|
|
78
|
+
firstRowValues,
|
|
79
|
+
{
|
|
80
|
+
rawResult: true,
|
|
81
|
+
lastInsertRowId,
|
|
82
|
+
changes,
|
|
83
|
+
}
|
|
46
84
|
);
|
|
47
85
|
}
|
|
48
86
|
|
|
@@ -85,9 +123,44 @@ export class SQLiteStatement {
|
|
|
85
123
|
return createSQLiteExecuteSyncResult<T>(
|
|
86
124
|
this.nativeDatabase,
|
|
87
125
|
this.nativeStatement,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
126
|
+
firstRowValues,
|
|
127
|
+
{
|
|
128
|
+
rawResult: false,
|
|
129
|
+
lastInsertRowId,
|
|
130
|
+
changes,
|
|
131
|
+
}
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Similar to [`executeSync()`](#executesyncparams) but returns the raw value array result instead of the row objects.
|
|
137
|
+
* @hidden Advanced use only.
|
|
138
|
+
*/
|
|
139
|
+
public executeForRawResultSync<T extends object>(
|
|
140
|
+
params: SQLiteBindParams
|
|
141
|
+
): SQLiteExecuteSyncResult<ValuesOf<T>>;
|
|
142
|
+
/**
|
|
143
|
+
* @hidden
|
|
144
|
+
*/
|
|
145
|
+
public executeForRawResultSync<T extends object>(
|
|
146
|
+
...params: SQLiteVariadicBindParams
|
|
147
|
+
): SQLiteExecuteSyncResult<ValuesOf<T>>;
|
|
148
|
+
public executeForRawResultSync<T extends object>(
|
|
149
|
+
...params: unknown[]
|
|
150
|
+
): SQLiteExecuteSyncResult<ValuesOf<T>> {
|
|
151
|
+
const { lastInsertRowId, changes, firstRowValues } = this.nativeStatement.runSync(
|
|
152
|
+
this.nativeDatabase,
|
|
153
|
+
...normalizeParams(...params)
|
|
154
|
+
);
|
|
155
|
+
return createSQLiteExecuteSyncResult<ValuesOf<T>>(
|
|
156
|
+
this.nativeDatabase,
|
|
157
|
+
this.nativeStatement,
|
|
158
|
+
firstRowValues,
|
|
159
|
+
{
|
|
160
|
+
rawResult: true,
|
|
161
|
+
lastInsertRowId,
|
|
162
|
+
changes,
|
|
163
|
+
}
|
|
91
164
|
);
|
|
92
165
|
}
|
|
93
166
|
|
|
@@ -260,6 +333,12 @@ export interface SQLiteExecuteSyncResult<T> extends IterableIterator<T> {
|
|
|
260
333
|
|
|
261
334
|
//#region Internals for SQLiteExecuteAsyncResult and SQLiteExecuteSyncResult
|
|
262
335
|
|
|
336
|
+
interface SQLiteExecuteResultOptions {
|
|
337
|
+
rawResult: boolean;
|
|
338
|
+
lastInsertRowId: number;
|
|
339
|
+
changes: number;
|
|
340
|
+
}
|
|
341
|
+
|
|
263
342
|
/**
|
|
264
343
|
* Create the `SQLiteExecuteAsyncResult` instance.
|
|
265
344
|
*
|
|
@@ -269,26 +348,24 @@ export interface SQLiteExecuteSyncResult<T> extends IterableIterator<T> {
|
|
|
269
348
|
async function createSQLiteExecuteAsyncResult<T>(
|
|
270
349
|
database: SQLiteAnyDatabase,
|
|
271
350
|
statement: NativeStatement,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
firstRowValues: SQLiteColumnValues | null
|
|
351
|
+
firstRowValues: SQLiteColumnValues | null,
|
|
352
|
+
options: SQLiteExecuteResultOptions
|
|
275
353
|
): Promise<SQLiteExecuteAsyncResult<T>> {
|
|
276
354
|
const instance = new SQLiteExecuteAsyncResultImpl<T>(
|
|
277
355
|
database,
|
|
278
356
|
statement,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
firstRowValues
|
|
357
|
+
firstRowValues,
|
|
358
|
+
options
|
|
282
359
|
);
|
|
283
360
|
const generator = instance.generatorAsync();
|
|
284
361
|
Object.defineProperties(generator, {
|
|
285
362
|
lastInsertRowId: {
|
|
286
|
-
value: lastInsertRowId,
|
|
363
|
+
value: options.lastInsertRowId,
|
|
287
364
|
enumerable: true,
|
|
288
365
|
writable: false,
|
|
289
366
|
configurable: true,
|
|
290
367
|
},
|
|
291
|
-
changes: { value: changes, enumerable: true, writable: false, configurable: true },
|
|
368
|
+
changes: { value: options.changes, enumerable: true, writable: false, configurable: true },
|
|
292
369
|
getFirstAsync: {
|
|
293
370
|
value: instance.getFirstAsync.bind(instance),
|
|
294
371
|
enumerable: true,
|
|
@@ -318,26 +395,19 @@ async function createSQLiteExecuteAsyncResult<T>(
|
|
|
318
395
|
function createSQLiteExecuteSyncResult<T>(
|
|
319
396
|
database: SQLiteAnyDatabase,
|
|
320
397
|
statement: NativeStatement,
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
firstRowValues: SQLiteColumnValues | null
|
|
398
|
+
firstRowValues: SQLiteColumnValues | null,
|
|
399
|
+
options: SQLiteExecuteResultOptions
|
|
324
400
|
): SQLiteExecuteSyncResult<T> {
|
|
325
|
-
const instance = new SQLiteExecuteSyncResultImpl<T>(
|
|
326
|
-
database,
|
|
327
|
-
statement,
|
|
328
|
-
lastInsertRowId,
|
|
329
|
-
changes,
|
|
330
|
-
firstRowValues
|
|
331
|
-
);
|
|
401
|
+
const instance = new SQLiteExecuteSyncResultImpl<T>(database, statement, firstRowValues, options);
|
|
332
402
|
const generator = instance.generatorSync();
|
|
333
403
|
Object.defineProperties(generator, {
|
|
334
404
|
lastInsertRowId: {
|
|
335
|
-
value: lastInsertRowId,
|
|
405
|
+
value: options.lastInsertRowId,
|
|
336
406
|
enumerable: true,
|
|
337
407
|
writable: false,
|
|
338
408
|
configurable: true,
|
|
339
409
|
},
|
|
340
|
-
changes: { value: changes, enumerable: true, writable: false, configurable: true },
|
|
410
|
+
changes: { value: options.changes, enumerable: true, writable: false, configurable: true },
|
|
341
411
|
getFirstSync: {
|
|
342
412
|
value: instance.getFirstSync.bind(instance),
|
|
343
413
|
enumerable: true,
|
|
@@ -368,9 +438,8 @@ class SQLiteExecuteAsyncResultImpl<T> {
|
|
|
368
438
|
constructor(
|
|
369
439
|
private readonly database: SQLiteAnyDatabase,
|
|
370
440
|
private readonly statement: NativeStatement,
|
|
371
|
-
|
|
372
|
-
public readonly
|
|
373
|
-
private firstRowValues: SQLiteColumnValues | null
|
|
441
|
+
private firstRowValues: SQLiteColumnValues | null,
|
|
442
|
+
public readonly options: SQLiteExecuteResultOptions
|
|
374
443
|
) {}
|
|
375
444
|
|
|
376
445
|
async getFirstAsync(): Promise<T | null> {
|
|
@@ -383,10 +452,12 @@ class SQLiteExecuteAsyncResultImpl<T> {
|
|
|
383
452
|
const columnNames = await this.getColumnNamesAsync();
|
|
384
453
|
const firstRowValues = this.popFirstRowValues();
|
|
385
454
|
if (firstRowValues != null) {
|
|
386
|
-
return
|
|
455
|
+
return composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
387
456
|
}
|
|
388
457
|
const firstRow = await this.statement.stepAsync(this.database);
|
|
389
|
-
return firstRow != null
|
|
458
|
+
return firstRow != null
|
|
459
|
+
? composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRow)
|
|
460
|
+
: null;
|
|
390
461
|
}
|
|
391
462
|
|
|
392
463
|
async getAllAsync(): Promise<T[]> {
|
|
@@ -400,9 +471,12 @@ class SQLiteExecuteAsyncResultImpl<T> {
|
|
|
400
471
|
const allRows = await this.statement.getAllAsync(this.database);
|
|
401
472
|
const firstRowValues = this.popFirstRowValues();
|
|
402
473
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
403
|
-
return
|
|
474
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, [
|
|
475
|
+
firstRowValues,
|
|
476
|
+
...allRows,
|
|
477
|
+
]);
|
|
404
478
|
}
|
|
405
|
-
return
|
|
479
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, allRows);
|
|
406
480
|
}
|
|
407
481
|
|
|
408
482
|
async *generatorAsync(): AsyncIterableIterator<T> {
|
|
@@ -410,14 +484,14 @@ class SQLiteExecuteAsyncResultImpl<T> {
|
|
|
410
484
|
const columnNames = await this.getColumnNamesAsync();
|
|
411
485
|
const firstRowValues = this.popFirstRowValues();
|
|
412
486
|
if (firstRowValues != null) {
|
|
413
|
-
yield
|
|
487
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
414
488
|
}
|
|
415
489
|
|
|
416
490
|
let result;
|
|
417
491
|
do {
|
|
418
492
|
result = await this.statement.stepAsync(this.database);
|
|
419
493
|
if (result != null) {
|
|
420
|
-
yield
|
|
494
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, result);
|
|
421
495
|
}
|
|
422
496
|
} while (result != null);
|
|
423
497
|
}
|
|
@@ -452,9 +526,8 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
452
526
|
constructor(
|
|
453
527
|
private readonly database: SQLiteAnyDatabase,
|
|
454
528
|
private readonly statement: NativeStatement,
|
|
455
|
-
|
|
456
|
-
public readonly
|
|
457
|
-
private firstRowValues: SQLiteColumnValues | null
|
|
529
|
+
private firstRowValues: SQLiteColumnValues | null,
|
|
530
|
+
public readonly options: SQLiteExecuteResultOptions
|
|
458
531
|
) {}
|
|
459
532
|
|
|
460
533
|
getFirstSync(): T | null {
|
|
@@ -466,10 +539,12 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
466
539
|
const columnNames = this.getColumnNamesSync();
|
|
467
540
|
const firstRowValues = this.popFirstRowValues();
|
|
468
541
|
if (firstRowValues != null) {
|
|
469
|
-
return
|
|
542
|
+
return composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
470
543
|
}
|
|
471
544
|
const firstRow = this.statement.stepSync(this.database);
|
|
472
|
-
return firstRow != null
|
|
545
|
+
return firstRow != null
|
|
546
|
+
? composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRow)
|
|
547
|
+
: null;
|
|
473
548
|
}
|
|
474
549
|
|
|
475
550
|
getAllSync(): T[] {
|
|
@@ -482,22 +557,25 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
482
557
|
const allRows = this.statement.getAllSync(this.database);
|
|
483
558
|
const firstRowValues = this.popFirstRowValues();
|
|
484
559
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
485
|
-
return
|
|
560
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, [
|
|
561
|
+
firstRowValues,
|
|
562
|
+
...allRows,
|
|
563
|
+
]);
|
|
486
564
|
}
|
|
487
|
-
return
|
|
565
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, allRows);
|
|
488
566
|
}
|
|
489
567
|
|
|
490
568
|
*generatorSync(): IterableIterator<T> {
|
|
491
569
|
const columnNames = this.getColumnNamesSync();
|
|
492
570
|
const firstRowValues = this.popFirstRowValues();
|
|
493
571
|
if (firstRowValues != null) {
|
|
494
|
-
yield
|
|
572
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
495
573
|
}
|
|
496
574
|
let result;
|
|
497
575
|
do {
|
|
498
576
|
result = this.statement.stepSync(this.database);
|
|
499
577
|
if (result != null) {
|
|
500
|
-
yield
|
|
578
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, result);
|
|
501
579
|
}
|
|
502
580
|
} while (result != null);
|
|
503
581
|
}
|
|
@@ -525,4 +603,24 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
525
603
|
}
|
|
526
604
|
}
|
|
527
605
|
|
|
606
|
+
function composeRowIfNeeded<T>(
|
|
607
|
+
rawResult: boolean,
|
|
608
|
+
columnNames: SQLiteColumnNames,
|
|
609
|
+
columnValues: SQLiteColumnValues
|
|
610
|
+
): T {
|
|
611
|
+
return rawResult
|
|
612
|
+
? (columnValues as T) // T would be a ValuesOf<> from caller
|
|
613
|
+
: composeRow<T>(columnNames, columnValues);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function composeRowsIfNeeded<T>(
|
|
617
|
+
rawResult: boolean,
|
|
618
|
+
columnNames: SQLiteColumnNames,
|
|
619
|
+
columnValuesList: SQLiteColumnValues[]
|
|
620
|
+
): T[] {
|
|
621
|
+
return rawResult
|
|
622
|
+
? (columnValuesList as T[]) // T[] would be a ValuesOf<>[] from caller
|
|
623
|
+
: composeRows<T>(columnNames, columnValuesList);
|
|
624
|
+
}
|
|
625
|
+
|
|
528
626
|
//#endregion
|