expo-sqlite 13.1.2 → 13.2.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/CHANGELOG.md +13 -0
- package/android/build.gradle +13 -3
- package/build/next/SQLiteStatement.d.ts +19 -0
- package/build/next/SQLiteStatement.d.ts.map +1 -1
- package/build/next/SQLiteStatement.js +82 -35
- package/build/next/SQLiteStatement.js.map +1 -1
- package/package.json +2 -2
- package/src/next/SQLiteStatement.ts +153 -47
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,19 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 13.2.1 — 2024-01-10
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Fixed building error on Windows. ([#26296](https://github.com/expo/expo/pull/26296) by [@kudo](https://github.com/kudo))
|
|
18
|
+
- Fixed a write query being executed twice when using `SQLiteDatabase.getAllAsync()` in expo-sqlite/next API. ([#26344](https://github.com/expo/expo/pull/26344) by [@kudo](https://github.com/kudo))
|
|
19
|
+
|
|
20
|
+
## 13.2.0 — 2023-12-21
|
|
21
|
+
|
|
22
|
+
### 🎉 New features
|
|
23
|
+
|
|
24
|
+
- 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))
|
|
25
|
+
|
|
13
26
|
## 13.1.2 — 2023-12-21
|
|
14
27
|
|
|
15
28
|
### 🐛 Bug fixes
|
package/android/build.gradle
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import org.apache.tools.ant.taskdefs.condition.Os
|
|
2
|
+
|
|
1
3
|
apply plugin: 'com.android.library'
|
|
2
4
|
apply plugin: 'kotlin-android'
|
|
3
5
|
apply plugin: 'maven-publish'
|
|
4
6
|
apply plugin: 'de.undercouch.download'
|
|
5
7
|
|
|
6
8
|
group = 'host.exp.exponent'
|
|
7
|
-
version = '13.1
|
|
9
|
+
version = '13.2.1'
|
|
8
10
|
|
|
9
11
|
def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
|
|
10
12
|
if (expoModulesCorePlugin.exists()) {
|
|
@@ -17,6 +19,14 @@ if (expoModulesCorePlugin.exists()) {
|
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
22
|
+
String toPlatformIndependentPath(File path) {
|
|
23
|
+
def result = path.toString()
|
|
24
|
+
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
|
|
25
|
+
result = result.replace(File.separatorChar, '/' as char)
|
|
26
|
+
}
|
|
27
|
+
return result
|
|
28
|
+
}
|
|
29
|
+
|
|
20
30
|
def SQLITE_VERSION = '3420000'
|
|
21
31
|
def customDownloadsDir = System.getenv("REACT_NATIVE_DOWNLOADS_DIR")
|
|
22
32
|
def downloadsDir = customDownloadsDir ? new File(customDownloadsDir) : new File("$buildDir/downloads")
|
|
@@ -106,13 +116,13 @@ android {
|
|
|
106
116
|
namespace "expo.modules.sqlite"
|
|
107
117
|
defaultConfig {
|
|
108
118
|
versionCode 18
|
|
109
|
-
versionName "13.1
|
|
119
|
+
versionName "13.2.1"
|
|
110
120
|
|
|
111
121
|
externalNativeBuild {
|
|
112
122
|
cmake {
|
|
113
123
|
abiFilters (*reactNativeArchitectures())
|
|
114
124
|
arguments "-DANDROID_STL=c++_shared",
|
|
115
|
-
"-DSQLITE3_SRC_DIR=${SQLITE3_SRC_DIR}"
|
|
125
|
+
"-DSQLITE3_SRC_DIR=${toPlatformIndependentPath(SQLITE3_SRC_DIR)}"
|
|
116
126
|
}
|
|
117
127
|
}
|
|
118
128
|
}
|
|
@@ -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,EAAE,wBAAwB,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,CAAC;IAkBjG;;;OAGG;IACI,wBAAwB,CAAC,CAAC,SAAS,MAAM,E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,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,36 +166,45 @@ 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) {
|
|
155
178
|
throw new Error('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.');
|
|
156
179
|
}
|
|
157
180
|
this.isStepCalled = true;
|
|
181
|
+
const firstRowValues = this.popFirstRowValues();
|
|
182
|
+
if (firstRowValues == null) {
|
|
183
|
+
// If the first row is empty, this SQL query may be a write operation. We should not call `statement.getAllAsync()` to write again.
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
158
186
|
const columnNames = await this.getColumnNamesAsync();
|
|
159
187
|
const allRows = await this.statement.getAllAsync(this.database);
|
|
160
|
-
const firstRowValues = this.popFirstRowValues();
|
|
161
188
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
162
|
-
return
|
|
189
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, [
|
|
190
|
+
firstRowValues,
|
|
191
|
+
...allRows,
|
|
192
|
+
]);
|
|
163
193
|
}
|
|
164
|
-
return
|
|
194
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, allRows);
|
|
165
195
|
}
|
|
166
196
|
async *generatorAsync() {
|
|
167
197
|
this.isStepCalled = true;
|
|
168
198
|
const columnNames = await this.getColumnNamesAsync();
|
|
169
199
|
const firstRowValues = this.popFirstRowValues();
|
|
170
200
|
if (firstRowValues != null) {
|
|
171
|
-
yield
|
|
201
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
172
202
|
}
|
|
173
203
|
let result;
|
|
174
204
|
do {
|
|
175
205
|
result = await this.statement.stepAsync(this.database);
|
|
176
206
|
if (result != null) {
|
|
177
|
-
yield
|
|
207
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, result);
|
|
178
208
|
}
|
|
179
209
|
} while (result != null);
|
|
180
210
|
}
|
|
@@ -201,17 +231,15 @@ class SQLiteExecuteAsyncResultImpl {
|
|
|
201
231
|
class SQLiteExecuteSyncResultImpl {
|
|
202
232
|
database;
|
|
203
233
|
statement;
|
|
204
|
-
lastInsertRowId;
|
|
205
|
-
changes;
|
|
206
234
|
firstRowValues;
|
|
235
|
+
options;
|
|
207
236
|
columnNames = null;
|
|
208
237
|
isStepCalled = false;
|
|
209
|
-
constructor(database, statement,
|
|
238
|
+
constructor(database, statement, firstRowValues, options) {
|
|
210
239
|
this.database = database;
|
|
211
240
|
this.statement = statement;
|
|
212
|
-
this.lastInsertRowId = lastInsertRowId;
|
|
213
|
-
this.changes = changes;
|
|
214
241
|
this.firstRowValues = firstRowValues;
|
|
242
|
+
this.options = options;
|
|
215
243
|
}
|
|
216
244
|
getFirstSync() {
|
|
217
245
|
if (this.isStepCalled) {
|
|
@@ -220,34 +248,43 @@ class SQLiteExecuteSyncResultImpl {
|
|
|
220
248
|
const columnNames = this.getColumnNamesSync();
|
|
221
249
|
const firstRowValues = this.popFirstRowValues();
|
|
222
250
|
if (firstRowValues != null) {
|
|
223
|
-
return
|
|
251
|
+
return composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
224
252
|
}
|
|
225
253
|
const firstRow = this.statement.stepSync(this.database);
|
|
226
|
-
return firstRow != null
|
|
254
|
+
return firstRow != null
|
|
255
|
+
? composeRowIfNeeded(this.options.rawResult, columnNames, firstRow)
|
|
256
|
+
: null;
|
|
227
257
|
}
|
|
228
258
|
getAllSync() {
|
|
229
259
|
if (this.isStepCalled) {
|
|
230
260
|
throw new Error('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.');
|
|
231
261
|
}
|
|
262
|
+
const firstRowValues = this.popFirstRowValues();
|
|
263
|
+
if (firstRowValues == null) {
|
|
264
|
+
// If the first row is empty, this SQL query may be a write operation. We should not call `statement.getAllAsync()` to write again.
|
|
265
|
+
return [];
|
|
266
|
+
}
|
|
232
267
|
const columnNames = this.getColumnNamesSync();
|
|
233
268
|
const allRows = this.statement.getAllSync(this.database);
|
|
234
|
-
const firstRowValues = this.popFirstRowValues();
|
|
235
269
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
236
|
-
return
|
|
270
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, [
|
|
271
|
+
firstRowValues,
|
|
272
|
+
...allRows,
|
|
273
|
+
]);
|
|
237
274
|
}
|
|
238
|
-
return
|
|
275
|
+
return composeRowsIfNeeded(this.options.rawResult, columnNames, allRows);
|
|
239
276
|
}
|
|
240
277
|
*generatorSync() {
|
|
241
278
|
const columnNames = this.getColumnNamesSync();
|
|
242
279
|
const firstRowValues = this.popFirstRowValues();
|
|
243
280
|
if (firstRowValues != null) {
|
|
244
|
-
yield
|
|
281
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, firstRowValues);
|
|
245
282
|
}
|
|
246
283
|
let result;
|
|
247
284
|
do {
|
|
248
285
|
result = this.statement.stepSync(this.database);
|
|
249
286
|
if (result != null) {
|
|
250
|
-
yield
|
|
287
|
+
yield composeRowIfNeeded(this.options.rawResult, columnNames, result);
|
|
251
288
|
}
|
|
252
289
|
} while (result != null);
|
|
253
290
|
}
|
|
@@ -271,5 +308,15 @@ class SQLiteExecuteSyncResultImpl {
|
|
|
271
308
|
return this.columnNames;
|
|
272
309
|
}
|
|
273
310
|
}
|
|
311
|
+
function composeRowIfNeeded(rawResult, columnNames, columnValues) {
|
|
312
|
+
return rawResult
|
|
313
|
+
? columnValues // T would be a ValuesOf<> from caller
|
|
314
|
+
: composeRow(columnNames, columnValues);
|
|
315
|
+
}
|
|
316
|
+
function composeRowsIfNeeded(rawResult, columnNames, columnValuesList) {
|
|
317
|
+
return rawResult
|
|
318
|
+
? columnValuesList // T[] would be a ValuesOf<>[] from caller
|
|
319
|
+
: composeRows(columnNames, columnValuesList);
|
|
320
|
+
}
|
|
274
321
|
//#endregion
|
|
275
322
|
//# 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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S,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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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,SAAS,kBAAkB,CACzB,SAAkB,EAClB,WAA8B,EAC9B,YAAgC;IAEhC,OAAO,SAAS;QACd,CAAC,CAAE,YAAkB,CAAC,sCAAsC;QAC5D,CAAC,CAAC,UAAU,CAAI,WAAW,EAAE,YAAY,CAAC,CAAC;AAC/C,CAAC;AAED,SAAS,mBAAmB,CAC1B,SAAkB,EAClB,WAA8B,EAC9B,gBAAsC;IAEtC,OAAO,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 firstRowValues = this.popFirstRowValues();\n if (firstRowValues == null) {\n // If the first row is empty, this SQL query may be a write operation. We should not call `statement.getAllAsync()` to write again.\n return [];\n }\n const columnNames = await this.getColumnNamesAsync();\n const allRows = await this.statement.getAllAsync(this.database);\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 firstRowValues = this.popFirstRowValues();\n if (firstRowValues == null) {\n // If the first row is empty, this SQL query may be a write operation. We should not call `statement.getAllAsync()` to write again.\n return [];\n }\n const columnNames = this.getColumnNamesSync();\n const allRows = this.statement.getAllSync(this.database);\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.1
|
|
3
|
+
"version": "13.2.1",
|
|
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": "ca014bf2516c7644ef303f4c21fdd68de4d99f76"
|
|
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[]> {
|
|
@@ -396,13 +467,20 @@ class SQLiteExecuteAsyncResultImpl<T> {
|
|
|
396
467
|
);
|
|
397
468
|
}
|
|
398
469
|
this.isStepCalled = true;
|
|
470
|
+
const firstRowValues = this.popFirstRowValues();
|
|
471
|
+
if (firstRowValues == null) {
|
|
472
|
+
// If the first row is empty, this SQL query may be a write operation. We should not call `statement.getAllAsync()` to write again.
|
|
473
|
+
return [];
|
|
474
|
+
}
|
|
399
475
|
const columnNames = await this.getColumnNamesAsync();
|
|
400
476
|
const allRows = await this.statement.getAllAsync(this.database);
|
|
401
|
-
const firstRowValues = this.popFirstRowValues();
|
|
402
477
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
403
|
-
return
|
|
478
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, [
|
|
479
|
+
firstRowValues,
|
|
480
|
+
...allRows,
|
|
481
|
+
]);
|
|
404
482
|
}
|
|
405
|
-
return
|
|
483
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, allRows);
|
|
406
484
|
}
|
|
407
485
|
|
|
408
486
|
async *generatorAsync(): AsyncIterableIterator<T> {
|
|
@@ -410,14 +488,14 @@ class SQLiteExecuteAsyncResultImpl<T> {
|
|
|
410
488
|
const columnNames = await this.getColumnNamesAsync();
|
|
411
489
|
const firstRowValues = this.popFirstRowValues();
|
|
412
490
|
if (firstRowValues != null) {
|
|
413
|
-
yield
|
|
491
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
414
492
|
}
|
|
415
493
|
|
|
416
494
|
let result;
|
|
417
495
|
do {
|
|
418
496
|
result = await this.statement.stepAsync(this.database);
|
|
419
497
|
if (result != null) {
|
|
420
|
-
yield
|
|
498
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, result);
|
|
421
499
|
}
|
|
422
500
|
} while (result != null);
|
|
423
501
|
}
|
|
@@ -452,9 +530,8 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
452
530
|
constructor(
|
|
453
531
|
private readonly database: SQLiteAnyDatabase,
|
|
454
532
|
private readonly statement: NativeStatement,
|
|
455
|
-
|
|
456
|
-
public readonly
|
|
457
|
-
private firstRowValues: SQLiteColumnValues | null
|
|
533
|
+
private firstRowValues: SQLiteColumnValues | null,
|
|
534
|
+
public readonly options: SQLiteExecuteResultOptions
|
|
458
535
|
) {}
|
|
459
536
|
|
|
460
537
|
getFirstSync(): T | null {
|
|
@@ -466,10 +543,12 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
466
543
|
const columnNames = this.getColumnNamesSync();
|
|
467
544
|
const firstRowValues = this.popFirstRowValues();
|
|
468
545
|
if (firstRowValues != null) {
|
|
469
|
-
return
|
|
546
|
+
return composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
470
547
|
}
|
|
471
548
|
const firstRow = this.statement.stepSync(this.database);
|
|
472
|
-
return firstRow != null
|
|
549
|
+
return firstRow != null
|
|
550
|
+
? composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRow)
|
|
551
|
+
: null;
|
|
473
552
|
}
|
|
474
553
|
|
|
475
554
|
getAllSync(): T[] {
|
|
@@ -478,26 +557,33 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
478
557
|
'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.'
|
|
479
558
|
);
|
|
480
559
|
}
|
|
560
|
+
const firstRowValues = this.popFirstRowValues();
|
|
561
|
+
if (firstRowValues == null) {
|
|
562
|
+
// If the first row is empty, this SQL query may be a write operation. We should not call `statement.getAllAsync()` to write again.
|
|
563
|
+
return [];
|
|
564
|
+
}
|
|
481
565
|
const columnNames = this.getColumnNamesSync();
|
|
482
566
|
const allRows = this.statement.getAllSync(this.database);
|
|
483
|
-
const firstRowValues = this.popFirstRowValues();
|
|
484
567
|
if (firstRowValues != null && firstRowValues.length > 0) {
|
|
485
|
-
return
|
|
568
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, [
|
|
569
|
+
firstRowValues,
|
|
570
|
+
...allRows,
|
|
571
|
+
]);
|
|
486
572
|
}
|
|
487
|
-
return
|
|
573
|
+
return composeRowsIfNeeded<T>(this.options.rawResult, columnNames, allRows);
|
|
488
574
|
}
|
|
489
575
|
|
|
490
576
|
*generatorSync(): IterableIterator<T> {
|
|
491
577
|
const columnNames = this.getColumnNamesSync();
|
|
492
578
|
const firstRowValues = this.popFirstRowValues();
|
|
493
579
|
if (firstRowValues != null) {
|
|
494
|
-
yield
|
|
580
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, firstRowValues);
|
|
495
581
|
}
|
|
496
582
|
let result;
|
|
497
583
|
do {
|
|
498
584
|
result = this.statement.stepSync(this.database);
|
|
499
585
|
if (result != null) {
|
|
500
|
-
yield
|
|
586
|
+
yield composeRowIfNeeded<T>(this.options.rawResult, columnNames, result);
|
|
501
587
|
}
|
|
502
588
|
} while (result != null);
|
|
503
589
|
}
|
|
@@ -525,4 +611,24 @@ class SQLiteExecuteSyncResultImpl<T> {
|
|
|
525
611
|
}
|
|
526
612
|
}
|
|
527
613
|
|
|
614
|
+
function composeRowIfNeeded<T>(
|
|
615
|
+
rawResult: boolean,
|
|
616
|
+
columnNames: SQLiteColumnNames,
|
|
617
|
+
columnValues: SQLiteColumnValues
|
|
618
|
+
): T {
|
|
619
|
+
return rawResult
|
|
620
|
+
? (columnValues as T) // T would be a ValuesOf<> from caller
|
|
621
|
+
: composeRow<T>(columnNames, columnValues);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function composeRowsIfNeeded<T>(
|
|
625
|
+
rawResult: boolean,
|
|
626
|
+
columnNames: SQLiteColumnNames,
|
|
627
|
+
columnValuesList: SQLiteColumnValues[]
|
|
628
|
+
): T[] {
|
|
629
|
+
return rawResult
|
|
630
|
+
? (columnValuesList as T[]) // T[] would be a ValuesOf<>[] from caller
|
|
631
|
+
: composeRows<T>(columnNames, columnValuesList);
|
|
632
|
+
}
|
|
633
|
+
|
|
528
634
|
//#endregion
|