expo-sqlite-mock 3.0.0 → 3.0.2
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/README.md +6 -3
- package/package.json +6 -2
- package/src/ExpoSQLiteNext.ts +21 -8
package/README.md
CHANGED
|
@@ -7,9 +7,9 @@ Use [expo-sqlite](https://docs.expo.dev/versions/latest/sdk/sqlite/) with jest.
|
|
|
7
7
|
|
|
8
8
|
## Notice
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
10
|
+
- **^3.0.0** is for expo-sqlite >=53.
|
|
11
|
+
- **^2.0.0** is for expo-sqlite ~52.
|
|
12
|
+
- **^1.0.0** is for expo-sqlite ~51.
|
|
13
13
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
@@ -53,6 +53,9 @@ it("test", async () => {
|
|
|
53
53
|
|
|
54
54
|
## Changelog
|
|
55
55
|
|
|
56
|
+
- **3.0.2**
|
|
57
|
+
- Constraint error handling.
|
|
58
|
+
|
|
56
59
|
- **3.0.0**
|
|
57
60
|
- Compatible with expo-sqlite ~15 and expo ~53.
|
|
58
61
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-sqlite-mock",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"homepage": "https://github.com/zfben/expo-sqlite-mock",
|
|
6
6
|
"repository": {
|
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
"jest": {
|
|
17
17
|
"preset": "jest-expo",
|
|
18
18
|
"testEnvironment": "node",
|
|
19
|
-
"testRegex": "/*\\.test\\.tsx?$"
|
|
19
|
+
"testRegex": "/*\\.test\\.tsx?$",
|
|
20
|
+
"maxWorkers": 1,
|
|
21
|
+
"setupFilesAfterEnv": [
|
|
22
|
+
"<rootDir>/src/__tests__/setup.ts"
|
|
23
|
+
]
|
|
20
24
|
},
|
|
21
25
|
"files": [
|
|
22
26
|
"src/ExpoSQLiteNext.ts",
|
package/src/ExpoSQLiteNext.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import sqlite3 from 'better-sqlite3'
|
|
2
2
|
|
|
3
3
|
import type {
|
|
4
|
+
SQLiteBindParams,
|
|
4
5
|
SQLiteBindValue,
|
|
5
6
|
SQLiteOpenOptions,
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
SQLiteRunResult,
|
|
8
|
+
} from 'expo-sqlite'
|
|
8
9
|
|
|
9
10
|
type SQLiteBindBlobParams = Record<string, Uint8Array>
|
|
10
|
-
type SQLiteBindPrimitiveParams = Record<
|
|
11
|
+
type SQLiteBindPrimitiveParams = Record<
|
|
12
|
+
string,
|
|
13
|
+
Exclude<SQLiteBindValue, Uint8Array>
|
|
14
|
+
>
|
|
11
15
|
type SQLiteColumnNames = string[]
|
|
12
16
|
type SQLiteColumnValues = any[]
|
|
13
17
|
|
|
@@ -91,17 +95,26 @@ class NativeStatement {
|
|
|
91
95
|
|
|
92
96
|
//#region Asynchronous API
|
|
93
97
|
|
|
94
|
-
public runAsync = (
|
|
98
|
+
public runAsync = async (
|
|
95
99
|
_database: NativeDatabase,
|
|
96
100
|
bindParams: SQLiteBindPrimitiveParams,
|
|
97
101
|
bindBlobParams: SQLiteBindBlobParams,
|
|
98
102
|
shouldPassAsArray: boolean
|
|
99
|
-
): Promise<SQLiteRunResult & { firstRowValues: SQLiteColumnValues }> =>
|
|
100
|
-
|
|
101
|
-
this._run(
|
|
103
|
+
): Promise<SQLiteRunResult & { firstRowValues: SQLiteColumnValues }> => {
|
|
104
|
+
try {
|
|
105
|
+
return await this._run(
|
|
102
106
|
normalizeSQLite3Args(bindParams, bindBlobParams, shouldPassAsArray)
|
|
103
107
|
)
|
|
104
|
-
)
|
|
108
|
+
} catch (error) {
|
|
109
|
+
if (error && typeof error === 'object' && 'code' in error) {
|
|
110
|
+
const enhancedError = new Error(error.message || error.code)
|
|
111
|
+
Object.assign(enhancedError, { code: error.code })
|
|
112
|
+
throw enhancedError
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
throw error
|
|
116
|
+
}
|
|
117
|
+
}
|
|
105
118
|
public stepAsync = (_database: NativeDatabase): Promise<any> => {
|
|
106
119
|
if (this.iterator == null) {
|
|
107
120
|
this.iterator = this.sqlite3Stmt.iterate()
|