expo-sqlite 12.2.0 → 13.0.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 +22 -0
- package/android/CMakeLists.txt +1 -1
- package/android/build.gradle +2 -2
- package/android/src/main/cpp/NativeStatementBinding.cpp +16 -15
- package/android/src/main/java/expo/modules/sqlite/NativeDatabase.kt +2 -0
- package/android/src/main/java/expo/modules/sqlite/NativeStatement.kt +2 -0
- package/android/src/main/java/expo/modules/sqlite/SQLExceptions.kt +6 -0
- package/android/src/main/java/expo/modules/sqlite/SQLiteModuleNext.kt +98 -95
- package/build/next/NativeStatement.d.ts +9 -13
- package/build/next/NativeStatement.d.ts.map +1 -1
- package/build/next/NativeStatement.js.map +1 -1
- package/build/next/Statement.d.ts +4 -6
- package/build/next/Statement.d.ts.map +1 -1
- package/build/next/Statement.js +36 -47
- package/build/next/Statement.js.map +1 -1
- package/ios/Exceptions.swift +12 -0
- package/ios/NativeDatabase.swift +1 -0
- package/ios/NativeStatement.swift +1 -0
- package/ios/SQLiteModule.swift +3 -4
- package/ios/SQLiteModuleNext.swift +108 -92
- package/ios/crsqlite.xcframework/Info.plist +4 -0
- package/ios/crsqlite.xcframework/ios-arm64/crsqlite.framework/Info.plist +4 -0
- package/package.json +2 -2
- package/src/next/NativeStatement.ts +36 -22
- package/src/next/Statement.ts +54 -49
package/src/next/Statement.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { NativeDatabase } from './NativeDatabase';
|
|
2
2
|
import {
|
|
3
|
+
BindBlobParams,
|
|
3
4
|
BindParams,
|
|
5
|
+
BindPrimitiveParams,
|
|
4
6
|
BindValue,
|
|
5
7
|
NativeStatement,
|
|
6
8
|
RunResult,
|
|
@@ -32,12 +34,7 @@ export class Statement {
|
|
|
32
34
|
*/
|
|
33
35
|
public runAsync(...params: VariadicBindParams): Promise<RunResult>;
|
|
34
36
|
public async runAsync(...params: unknown[]): Promise<RunResult> {
|
|
35
|
-
|
|
36
|
-
if (shouldPassAsObject) {
|
|
37
|
-
return await this.nativeStatement.objectRunAsync(this.nativeDatabase, bindParams);
|
|
38
|
-
} else {
|
|
39
|
-
return await this.nativeStatement.arrayRunAsync(this.nativeDatabase, bindParams);
|
|
40
|
-
}
|
|
37
|
+
return await this.nativeStatement.runAsync(this.nativeDatabase, ...normalizeParams(...params));
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
/**
|
|
@@ -58,15 +55,13 @@ export class Statement {
|
|
|
58
55
|
*/
|
|
59
56
|
public eachAsync<T>(...params: VariadicBindParams): AsyncIterableIterator<T>;
|
|
60
57
|
public async *eachAsync<T>(...params: unknown[]): AsyncIterableIterator<T> {
|
|
61
|
-
const
|
|
62
|
-
const func =
|
|
63
|
-
? this.nativeStatement.objectGetAsync.bind(this.nativeStatement)
|
|
64
|
-
: this.nativeStatement.arrayGetAsync.bind(this.nativeStatement);
|
|
58
|
+
const paramTuple = normalizeParams(...params);
|
|
59
|
+
const func = this.nativeStatement.getAsync.bind(this.nativeStatement);
|
|
65
60
|
|
|
66
61
|
const columnNames = await this.getColumnNamesAsync();
|
|
67
62
|
let result = null;
|
|
68
63
|
do {
|
|
69
|
-
result = await func(this.nativeDatabase,
|
|
64
|
+
result = await func(this.nativeDatabase, ...paramTuple);
|
|
70
65
|
if (result != null) {
|
|
71
66
|
yield composeRow<T>(columnNames, result);
|
|
72
67
|
}
|
|
@@ -83,11 +78,11 @@ export class Statement {
|
|
|
83
78
|
*/
|
|
84
79
|
public getAsync<T>(...params: VariadicBindParams): Promise<T | null>;
|
|
85
80
|
public async getAsync<T>(...params: unknown[]): Promise<T | null> {
|
|
86
|
-
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
87
81
|
const columnNames = await this.getColumnNamesAsync();
|
|
88
|
-
const columnValues =
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
const columnValues = await this.nativeStatement.getAsync(
|
|
83
|
+
this.nativeDatabase,
|
|
84
|
+
...normalizeParams(...params)
|
|
85
|
+
);
|
|
91
86
|
return columnValues != null ? composeRow<T>(columnNames, columnValues) : null;
|
|
92
87
|
}
|
|
93
88
|
|
|
@@ -101,11 +96,11 @@ export class Statement {
|
|
|
101
96
|
*/
|
|
102
97
|
public allAsync<T>(...params: VariadicBindParams): Promise<T[]>;
|
|
103
98
|
public async allAsync<T>(...params: unknown[]): Promise<T[]> {
|
|
104
|
-
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
105
99
|
const columnNames = await this.getColumnNamesAsync();
|
|
106
|
-
const columnValuesList =
|
|
107
|
-
|
|
108
|
-
|
|
100
|
+
const columnValuesList = await this.nativeStatement.getAllAsync(
|
|
101
|
+
this.nativeDatabase,
|
|
102
|
+
...normalizeParams(...params)
|
|
103
|
+
);
|
|
109
104
|
return composeRows<T>(columnNames, columnValuesList);
|
|
110
105
|
}
|
|
111
106
|
|
|
@@ -146,12 +141,7 @@ export class Statement {
|
|
|
146
141
|
*/
|
|
147
142
|
public runSync(...params: VariadicBindParams): RunResult;
|
|
148
143
|
public runSync(...params: unknown[]): RunResult {
|
|
149
|
-
|
|
150
|
-
if (shouldPassAsObject) {
|
|
151
|
-
return this.nativeStatement.objectRunSync(this.nativeDatabase, bindParams);
|
|
152
|
-
} else {
|
|
153
|
-
return this.nativeStatement.arrayRunSync(this.nativeDatabase, bindParams);
|
|
154
|
-
}
|
|
144
|
+
return this.nativeStatement.runSync(this.nativeDatabase, ...normalizeParams(...params));
|
|
155
145
|
}
|
|
156
146
|
|
|
157
147
|
/**
|
|
@@ -165,15 +155,13 @@ export class Statement {
|
|
|
165
155
|
*/
|
|
166
156
|
public eachSync<T>(...params: VariadicBindParams): IterableIterator<T>;
|
|
167
157
|
public *eachSync<T>(...params: unknown[]): IterableIterator<T> {
|
|
168
|
-
const
|
|
169
|
-
const func =
|
|
170
|
-
? this.nativeStatement.objectGetSync.bind(this.nativeStatement)
|
|
171
|
-
: this.nativeStatement.arrayGetSync.bind(this.nativeStatement);
|
|
158
|
+
const paramTuple = normalizeParams(...params);
|
|
159
|
+
const func = this.nativeStatement.getSync.bind(this.nativeStatement);
|
|
172
160
|
|
|
173
161
|
const columnNames = this.getColumnNamesSync();
|
|
174
162
|
let result = null;
|
|
175
163
|
do {
|
|
176
|
-
result = func(this.nativeDatabase,
|
|
164
|
+
result = func(this.nativeDatabase, ...paramTuple);
|
|
177
165
|
if (result != null) {
|
|
178
166
|
yield composeRow<T>(columnNames, result);
|
|
179
167
|
}
|
|
@@ -191,11 +179,11 @@ export class Statement {
|
|
|
191
179
|
*/
|
|
192
180
|
public getSync<T>(...params: VariadicBindParams): T | null;
|
|
193
181
|
public getSync<T>(...params: unknown[]): T | null {
|
|
194
|
-
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
195
182
|
const columnNames = this.getColumnNamesSync();
|
|
196
|
-
const columnValues =
|
|
197
|
-
|
|
198
|
-
|
|
183
|
+
const columnValues = this.nativeStatement.getSync(
|
|
184
|
+
this.nativeDatabase,
|
|
185
|
+
...normalizeParams(...params)
|
|
186
|
+
);
|
|
199
187
|
return columnValues != null ? composeRow<T>(columnNames, columnValues) : null;
|
|
200
188
|
}
|
|
201
189
|
|
|
@@ -210,11 +198,11 @@ export class Statement {
|
|
|
210
198
|
*/
|
|
211
199
|
public allSync<T>(...params: VariadicBindParams): T[];
|
|
212
200
|
public allSync<T>(...params: unknown[]): T[] {
|
|
213
|
-
const { params: bindParams, shouldPassAsObject } = normalizeParams(...params);
|
|
214
201
|
const columnNames = this.getColumnNamesSync();
|
|
215
|
-
const columnValuesList =
|
|
216
|
-
|
|
217
|
-
|
|
202
|
+
const columnValuesList = this.nativeStatement.getAllSync(
|
|
203
|
+
this.nativeDatabase,
|
|
204
|
+
...normalizeParams(...params)
|
|
205
|
+
);
|
|
218
206
|
return composeRows<T>(columnNames, columnValuesList);
|
|
219
207
|
}
|
|
220
208
|
|
|
@@ -246,25 +234,42 @@ export class Statement {
|
|
|
246
234
|
}
|
|
247
235
|
|
|
248
236
|
/**
|
|
249
|
-
* Normalize the bind params to
|
|
237
|
+
* Normalize the bind params to data structure that can be passed to native module.
|
|
238
|
+
* The data structure is a tuple of [primitiveParams, blobParams, shouldPassAsArray].
|
|
250
239
|
* @hidden
|
|
251
240
|
*/
|
|
252
|
-
export function normalizeParams(...params: any[]): {
|
|
253
|
-
params: BindParams;
|
|
254
|
-
shouldPassAsObject: boolean;
|
|
255
|
-
} {
|
|
241
|
+
export function normalizeParams(...params: any[]): [BindPrimitiveParams, BindBlobParams, boolean] {
|
|
256
242
|
let bindParams = params.length > 1 ? params : (params[0] as BindParams);
|
|
257
243
|
if (bindParams == null) {
|
|
258
244
|
bindParams = [];
|
|
259
245
|
}
|
|
260
|
-
if (
|
|
246
|
+
if (
|
|
247
|
+
typeof bindParams !== 'object' ||
|
|
248
|
+
bindParams instanceof ArrayBuffer ||
|
|
249
|
+
ArrayBuffer.isView(bindParams)
|
|
250
|
+
) {
|
|
261
251
|
bindParams = [bindParams];
|
|
262
252
|
}
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
253
|
+
const shouldPassAsArray = Array.isArray(bindParams);
|
|
254
|
+
if (Array.isArray(bindParams)) {
|
|
255
|
+
bindParams = bindParams.reduce<Record<string, BindValue>>((acc, value, index) => {
|
|
256
|
+
acc[index] = value;
|
|
257
|
+
return acc;
|
|
258
|
+
}, {});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const primitiveParams: BindPrimitiveParams = {};
|
|
262
|
+
const blobParams: BindBlobParams = {};
|
|
263
|
+
for (const key in bindParams) {
|
|
264
|
+
const value = bindParams[key];
|
|
265
|
+
if (value instanceof Uint8Array) {
|
|
266
|
+
blobParams[key] = value;
|
|
267
|
+
} else {
|
|
268
|
+
primitiveParams[key] = value;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
return [primitiveParams, blobParams, shouldPassAsArray];
|
|
268
273
|
}
|
|
269
274
|
|
|
270
275
|
/**
|