react-native-nitro-sqlite 9.1.11 → 9.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/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/checksums/md5-checksums.bin +0 -0
- package/android/.gradle/8.9/checksums/sha1-checksums.bin +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/CMakeLists.txt +0 -1
- package/android/build.gradle +2 -2
- package/cpp/NitroSQLiteException.hpp +16 -13
- package/cpp/importSqlFile.cpp +2 -2
- package/cpp/logs.hpp +14 -12
- package/cpp/operations.cpp +29 -28
- package/cpp/operations.hpp +1 -1
- package/cpp/specs/HybridNativeQueryResult.hpp +1 -1
- package/cpp/specs/HybridNitroSQLite.cpp +5 -5
- package/cpp/specs/HybridNitroSQLite.hpp +16 -13
- package/cpp/sqliteExecuteBatch.cpp +1 -1
- package/cpp/types.hpp +3 -3
- package/cpp/utils.hpp +2 -3
- package/lib/commonjs/DatabaseQueue.js +104 -0
- package/lib/commonjs/DatabaseQueue.js.map +1 -0
- package/lib/commonjs/NitroSQLiteError.js +50 -0
- package/lib/commonjs/NitroSQLiteError.js.map +1 -0
- package/lib/commonjs/index.js +9 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nitro.js +1 -2
- package/lib/commonjs/nitro.js.map +1 -1
- package/lib/commonjs/nullHandling.js +1 -1
- package/lib/commonjs/nullHandling.js.map +1 -1
- package/lib/commonjs/operations/execute.js +14 -6
- package/lib/commonjs/operations/execute.js.map +1 -1
- package/lib/commonjs/operations/executeBatch.js +17 -4
- package/lib/commonjs/operations/executeBatch.js.map +1 -1
- package/lib/commonjs/operations/session.js +17 -15
- package/lib/commonjs/operations/session.js.map +1 -1
- package/lib/commonjs/operations/transaction.js +26 -54
- package/lib/commonjs/operations/transaction.js.map +1 -1
- package/lib/commonjs/typeORM.js +1 -2
- package/lib/commonjs/typeORM.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/module/DatabaseQueue.js +91 -0
- package/lib/module/DatabaseQueue.js.map +1 -0
- package/lib/module/NitroSQLiteError.js +45 -0
- package/lib/module/NitroSQLiteError.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/nitro.js +0 -1
- package/lib/module/nitro.js.map +1 -1
- package/lib/module/nullHandling.js +1 -1
- package/lib/module/nullHandling.js.map +1 -1
- package/lib/module/operations/execute.js +13 -6
- package/lib/module/operations/execute.js.map +1 -1
- package/lib/module/operations/executeBatch.js +16 -4
- package/lib/module/operations/executeBatch.js.map +1 -1
- package/lib/module/operations/session.js +17 -14
- package/lib/module/operations/session.js.map +1 -1
- package/lib/module/operations/transaction.js +25 -54
- package/lib/module/operations/transaction.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/typescript/commonjs/DatabaseQueue.d.ts +20 -0
- package/lib/typescript/commonjs/DatabaseQueue.d.ts.map +1 -0
- package/lib/typescript/commonjs/NitroSQLiteError.d.ts +13 -0
- package/lib/typescript/commonjs/NitroSQLiteError.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +4 -3
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/nitro.d.ts +0 -5
- package/lib/typescript/commonjs/nitro.d.ts.map +1 -1
- package/lib/typescript/commonjs/nullHandling.d.ts +1 -1
- package/lib/typescript/commonjs/nullHandling.d.ts.map +1 -1
- package/lib/typescript/commonjs/operations/execute.d.ts.map +1 -1
- package/lib/typescript/commonjs/operations/executeBatch.d.ts.map +1 -1
- package/lib/typescript/commonjs/operations/session.d.ts +0 -2
- package/lib/typescript/commonjs/operations/session.d.ts.map +1 -1
- package/lib/typescript/commonjs/operations/transaction.d.ts +1 -4
- package/lib/typescript/commonjs/operations/transaction.d.ts.map +1 -1
- package/lib/typescript/commonjs/types.d.ts +1 -1
- package/lib/typescript/commonjs/types.d.ts.map +1 -1
- package/lib/typescript/module/DatabaseQueue.d.ts +20 -0
- package/lib/typescript/module/DatabaseQueue.d.ts.map +1 -0
- package/lib/typescript/module/NitroSQLiteError.d.ts +13 -0
- package/lib/typescript/module/NitroSQLiteError.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +4 -3
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/nitro.d.ts +0 -5
- package/lib/typescript/module/nitro.d.ts.map +1 -1
- package/lib/typescript/module/nullHandling.d.ts +1 -1
- package/lib/typescript/module/nullHandling.d.ts.map +1 -1
- package/lib/typescript/module/operations/execute.d.ts.map +1 -1
- package/lib/typescript/module/operations/executeBatch.d.ts.map +1 -1
- package/lib/typescript/module/operations/session.d.ts +0 -2
- package/lib/typescript/module/operations/session.d.ts.map +1 -1
- package/lib/typescript/module/operations/transaction.d.ts +1 -4
- package/lib/typescript/module/operations/transaction.d.ts.map +1 -1
- package/lib/typescript/module/types.d.ts +1 -1
- package/lib/typescript/module/types.d.ts.map +1 -1
- package/package.json +15 -15
- package/src/DatabaseQueue.ts +129 -0
- package/src/NitroSQLiteError.ts +45 -0
- package/src/index.ts +3 -2
- package/src/nitro.ts +0 -6
- package/src/nullHandling.ts +8 -4
- package/src/operations/execute.ts +27 -19
- package/src/operations/executeBatch.ts +30 -10
- package/src/operations/session.ts +21 -21
- package/src/operations/transaction.ts +42 -85
- package/src/specs/NitroSQLite.nitro.ts +5 -5
- package/src/typeORM.ts +6 -6
- package/src/types.ts +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts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,GAAG,CAAC,CAAA;AAErB,MAAM,MAAM,iBAAiB,GAAG,CAAC,GAAG,SAAS,cAAc,GAAG,cAAc,EAC1E,KAAK,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,iBAAiB,KACvB,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAA;AAE9B,MAAM,WAAW,WAAW;IAC1B,MAAM,IAAI,WAAW,CAAA;IACrB,QAAQ,IAAI,WAAW,CAAA;IACvB,OAAO,EAAE,YAAY,CAAA;IACrB,YAAY,EAAE,iBAAiB,CAAA;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAAA;CACjD;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,uBAAuB,GAAG,uBAAuB,EAAE,CAAA;CAC7D;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,gBAAgB;IACtD,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-sqlite",
|
|
3
|
-
"version": "9.1
|
|
3
|
+
"version": "9.2.1",
|
|
4
4
|
"description": "Fast SQLite library for React Native built using Nitro Modules",
|
|
5
|
-
"
|
|
6
|
-
"main": "./lib/commonjs/index",
|
|
5
|
+
"main": "./lib/module/index",
|
|
7
6
|
"module": "./lib/module/index",
|
|
8
|
-
"types": "./lib/typescript/
|
|
7
|
+
"types": "./lib/typescript/module/index.d.ts",
|
|
8
|
+
"source": "./src/index",
|
|
9
|
+
"react-native": "./src/index",
|
|
9
10
|
"exports": {
|
|
10
11
|
".": {
|
|
11
12
|
"import": {
|
|
@@ -36,14 +37,13 @@
|
|
|
36
37
|
"!**/__mocks__"
|
|
37
38
|
],
|
|
38
39
|
"scripts": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"typescript": "tsc --noEmit",
|
|
40
|
+
"build": "bun typecheck && bob build",
|
|
41
|
+
"specs": "bun typecheck && bun nitro-codegen --logLevel=\"debug\"",
|
|
42
|
+
"typecheck": "tsc --noEmit",
|
|
43
43
|
"lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
|
|
44
|
-
"lint-ci": "eslint \"**/*.{js,ts,tsx}\" -f @jamesacarr/github-actions",
|
|
45
44
|
"test": "jest",
|
|
46
|
-
"release": "release-it"
|
|
45
|
+
"release": "release-it",
|
|
46
|
+
"prepublishOnly": "bun run build"
|
|
47
47
|
},
|
|
48
48
|
"keywords": [
|
|
49
49
|
"react-native",
|
|
@@ -66,13 +66,13 @@
|
|
|
66
66
|
"registry": "https://registry.npmjs.org/"
|
|
67
67
|
},
|
|
68
68
|
"dependencies": {
|
|
69
|
-
"typeorm": "
|
|
69
|
+
"typeorm": "0.3.20"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"jest": "^
|
|
72
|
+
"jest": "^30.2.0",
|
|
73
73
|
"nitro-codegen": "0.27.2",
|
|
74
|
-
"react": "19.
|
|
75
|
-
"react-native": "0.
|
|
74
|
+
"react": "19.1.1",
|
|
75
|
+
"react-native": "0.82.1",
|
|
76
76
|
"react-native-builder-bob": "^0.31.0",
|
|
77
77
|
"react-native-nitro-modules": "0.27.2"
|
|
78
78
|
},
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"release": false
|
|
101
101
|
},
|
|
102
102
|
"hooks": {
|
|
103
|
-
"before:init": "bun
|
|
103
|
+
"before:init": "bun typecheck && bun lint",
|
|
104
104
|
"after:bump": "bun run build"
|
|
105
105
|
}
|
|
106
106
|
},
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import NitroSQLiteError from './NitroSQLiteError'
|
|
2
|
+
|
|
3
|
+
export interface QueuedOperation {
|
|
4
|
+
/**
|
|
5
|
+
* Starts the operation
|
|
6
|
+
*/
|
|
7
|
+
start: () => void
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export type DatabaseQueue = {
|
|
11
|
+
queue: QueuedOperation[]
|
|
12
|
+
inProgress: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const databaseQueues = new Map<string, DatabaseQueue>()
|
|
16
|
+
|
|
17
|
+
export function openDatabaseQueue(dbName: string) {
|
|
18
|
+
if (isDatabaseOpen(dbName)) {
|
|
19
|
+
throw new NitroSQLiteError(
|
|
20
|
+
`Database ${dbName} is already open. There is already a connection to the database.`,
|
|
21
|
+
)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
databaseQueues.set(dbName, { queue: [], inProgress: false })
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function closeDatabaseQueue(dbName: string) {
|
|
28
|
+
const databaseQueue = getDatabaseQueue(dbName)
|
|
29
|
+
|
|
30
|
+
if (databaseQueue.inProgress || databaseQueue.queue.length > 0) {
|
|
31
|
+
console.warn(
|
|
32
|
+
`Database queue for ${dbName} has operations in the queue. Closing anyway.`,
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
databaseQueues.delete(dbName)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function isDatabaseOpen(dbName: string) {
|
|
40
|
+
return databaseQueues.has(dbName)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function throwIfDatabaseIsNotOpen(dbName: string) {
|
|
44
|
+
if (!isDatabaseOpen(dbName))
|
|
45
|
+
throw new NitroSQLiteError(
|
|
46
|
+
`Database ${dbName} is not open. There is no connection to the database.`,
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function getDatabaseQueue(dbName: string) {
|
|
51
|
+
throwIfDatabaseIsNotOpen(dbName)
|
|
52
|
+
|
|
53
|
+
const queue = databaseQueues.get(dbName)!
|
|
54
|
+
return queue
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function openDatabase(dbName: string) {
|
|
58
|
+
databaseQueues.set(dbName, { queue: [], inProgress: false })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export function closeDatabase(dbName: string) {
|
|
62
|
+
databaseQueues.delete(dbName)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function queueOperationAsync<Result>(
|
|
66
|
+
dbName: string,
|
|
67
|
+
callback: () => Promise<Result>,
|
|
68
|
+
) {
|
|
69
|
+
const databaseQueue = getDatabaseQueue(dbName)
|
|
70
|
+
|
|
71
|
+
return new Promise<Result>((resolve, reject) => {
|
|
72
|
+
async function start() {
|
|
73
|
+
try {
|
|
74
|
+
const result = await callback()
|
|
75
|
+
resolve(result)
|
|
76
|
+
} catch (error) {
|
|
77
|
+
reject(error)
|
|
78
|
+
} finally {
|
|
79
|
+
databaseQueue.inProgress = false
|
|
80
|
+
startOperationAsync(dbName)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const operation: QueuedOperation = {
|
|
85
|
+
start,
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
databaseQueue.queue.push(operation)
|
|
89
|
+
startOperationAsync(dbName)
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function startOperationAsync(dbName: string) {
|
|
94
|
+
const queue = getDatabaseQueue(dbName)
|
|
95
|
+
|
|
96
|
+
// Queue is empty or in progress. Bail out.
|
|
97
|
+
if (queue.inProgress || queue.queue.length === 0) {
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
queue.inProgress = true
|
|
102
|
+
|
|
103
|
+
const operation = queue.queue.shift()!
|
|
104
|
+
setImmediate(() => {
|
|
105
|
+
operation.start()
|
|
106
|
+
})
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function startOperationSync<
|
|
110
|
+
OperationCallback extends () => Result,
|
|
111
|
+
Result = void,
|
|
112
|
+
>(dbName: string, callback: OperationCallback) {
|
|
113
|
+
const databaseQueue = getDatabaseQueue(dbName)
|
|
114
|
+
|
|
115
|
+
// Database is busy - cannot execute synchronously
|
|
116
|
+
if (databaseQueue.inProgress || databaseQueue.queue.length > 0) {
|
|
117
|
+
throw new NitroSQLiteError(
|
|
118
|
+
`Cannot run synchronous operation on database. Database ${dbName} is busy with another operation.`,
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Execute synchronously
|
|
123
|
+
databaseQueue.inProgress = true
|
|
124
|
+
try {
|
|
125
|
+
return callback()
|
|
126
|
+
} finally {
|
|
127
|
+
databaseQueue.inProgress = false
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const NITRO_SQLITE_ERROR_NAME = 'NitroSQLiteError' as const
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Custom error class for NitroSQLite operations
|
|
5
|
+
* Extends the native Error class with proper prototype chain and error handling
|
|
6
|
+
*/
|
|
7
|
+
export default class NitroSQLiteError extends Error {
|
|
8
|
+
constructor(message: string, options?: ErrorOptions) {
|
|
9
|
+
super(message, options)
|
|
10
|
+
this.name = NITRO_SQLITE_ERROR_NAME
|
|
11
|
+
|
|
12
|
+
// Maintains proper prototype chain for instanceof checks
|
|
13
|
+
Object.setPrototypeOf(this, NitroSQLiteError.prototype)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Converts an unknown error to a NitroSQLiteError
|
|
18
|
+
* Preserves stack traces and error causes when available
|
|
19
|
+
*/
|
|
20
|
+
static fromError(error: unknown): NitroSQLiteError {
|
|
21
|
+
if (error instanceof NitroSQLiteError) {
|
|
22
|
+
return error
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (error instanceof Error) {
|
|
26
|
+
const nitroSQLiteError = new NitroSQLiteError(error.message, {
|
|
27
|
+
cause: error.cause,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
// Preserve original stack trace if available
|
|
31
|
+
if (error.stack) {
|
|
32
|
+
nitroSQLiteError.stack = error.stack
|
|
33
|
+
}
|
|
34
|
+
return nitroSQLiteError
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (typeof error === 'string') {
|
|
38
|
+
return new NitroSQLiteError(error)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return new NitroSQLiteError('Unknown error occurred', {
|
|
42
|
+
cause: error,
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -4,8 +4,6 @@ import { open } from './operations/session'
|
|
|
4
4
|
import { execute, executeAsync } from './operations/execute'
|
|
5
5
|
import { init } from './OnLoad'
|
|
6
6
|
import { executeBatch, executeBatchAsync } from './operations/executeBatch'
|
|
7
|
-
export type * from './types'
|
|
8
|
-
export { typeORMDriver } from './typeORM'
|
|
9
7
|
|
|
10
8
|
init()
|
|
11
9
|
|
|
@@ -30,3 +28,6 @@ export {
|
|
|
30
28
|
isSimpleNullHandlingEnabled,
|
|
31
29
|
enableSimpleNullHandling,
|
|
32
30
|
} from './nullHandling'
|
|
31
|
+
export { default as NitroSQLiteError } from './NitroSQLiteError'
|
|
32
|
+
export type * from './types'
|
|
33
|
+
export { typeORMDriver } from './typeORM'
|
package/src/nitro.ts
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
2
|
import type { NitroSQLite as NitroSQLiteSpec } from './specs/NitroSQLite.nitro'
|
|
3
|
-
import type { PendingTransaction } from './operations/transaction'
|
|
4
3
|
|
|
5
4
|
export const HybridNitroSQLite =
|
|
6
5
|
NitroModules.createHybridObject<NitroSQLiteSpec>('NitroSQLite')
|
|
7
|
-
|
|
8
|
-
export const locks: Record<
|
|
9
|
-
string,
|
|
10
|
-
{ queue: PendingTransaction[]; inProgress: boolean }
|
|
11
|
-
> = {}
|
package/src/nullHandling.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { SQLiteQueryParamItem } from './types'
|
|
|
4
4
|
let ENABLE_SIMPLE_NULL_HANDLING = false
|
|
5
5
|
|
|
6
6
|
export function enableSimpleNullHandling(
|
|
7
|
-
shouldEnableSimpleNullHandling = true
|
|
7
|
+
shouldEnableSimpleNullHandling = true,
|
|
8
8
|
) {
|
|
9
9
|
ENABLE_SIMPLE_NULL_HANDLING = shouldEnableSimpleNullHandling
|
|
10
10
|
}
|
|
@@ -14,15 +14,19 @@ export function isSimpleNullHandlingEnabled() {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export const NITRO_SQLITE_NULL: SQLiteNullValue = { isNitroSQLiteNull: true }
|
|
17
|
-
export function isNitroSQLiteNull(value:
|
|
18
|
-
if (
|
|
17
|
+
export function isNitroSQLiteNull(value: unknown): value is SQLiteNullValue {
|
|
18
|
+
if (
|
|
19
|
+
value !== null &&
|
|
20
|
+
typeof value === 'object' &&
|
|
21
|
+
'isNitroSQLiteNull' in value
|
|
22
|
+
) {
|
|
19
23
|
return true
|
|
20
24
|
}
|
|
21
25
|
return false
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
export function replaceWithNativeNullValue(
|
|
25
|
-
value: SQLiteQueryParamItem
|
|
29
|
+
value: SQLiteQueryParamItem,
|
|
26
30
|
): SQLiteValue {
|
|
27
31
|
if (value === undefined || value === null) {
|
|
28
32
|
return NITRO_SQLITE_NULL
|
|
@@ -8,45 +8,53 @@ import type {
|
|
|
8
8
|
SQLiteQueryParams,
|
|
9
9
|
QueryResultRow,
|
|
10
10
|
} from '../types'
|
|
11
|
+
import NitroSQLiteError from '../NitroSQLiteError'
|
|
11
12
|
|
|
12
13
|
export function execute<Row extends QueryResultRow = never>(
|
|
13
14
|
dbName: string,
|
|
14
15
|
query: string,
|
|
15
|
-
params?: SQLiteQueryParams
|
|
16
|
+
params?: SQLiteQueryParams,
|
|
16
17
|
): QueryResult<Row> {
|
|
17
18
|
const transformedParams = isSimpleNullHandlingEnabled()
|
|
18
19
|
? toNativeQueryParams(params)
|
|
19
20
|
: (params as NativeSQLiteQueryParams)
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
try {
|
|
23
|
+
const nativeResult = HybridNitroSQLite.execute(
|
|
24
|
+
dbName,
|
|
25
|
+
query,
|
|
26
|
+
transformedParams,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
return buildJsQueryResult<Row>(nativeResult)
|
|
30
|
+
} catch (error) {
|
|
31
|
+
throw NitroSQLiteError.fromError(error)
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
|
|
30
35
|
export async function executeAsync<Row extends QueryResultRow = never>(
|
|
31
36
|
dbName: string,
|
|
32
37
|
query: string,
|
|
33
|
-
params?: SQLiteQueryParams
|
|
38
|
+
params?: SQLiteQueryParams,
|
|
34
39
|
): Promise<QueryResult<Row>> {
|
|
35
40
|
const transformedParams = isSimpleNullHandlingEnabled()
|
|
36
41
|
? toNativeQueryParams(params)
|
|
37
42
|
: (params as NativeSQLiteQueryParams)
|
|
38
43
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
try {
|
|
45
|
+
const nativeResult = await HybridNitroSQLite.executeAsync(
|
|
46
|
+
dbName,
|
|
47
|
+
query,
|
|
48
|
+
transformedParams,
|
|
49
|
+
)
|
|
50
|
+
return buildJsQueryResult<Row>(nativeResult)
|
|
51
|
+
} catch (error) {
|
|
52
|
+
throw NitroSQLiteError.fromError(error)
|
|
53
|
+
}
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
function toNativeQueryParams(
|
|
49
|
-
params: SQLiteQueryParams | undefined
|
|
57
|
+
params: SQLiteQueryParams | undefined,
|
|
50
58
|
): NativeSQLiteQueryParams | undefined {
|
|
51
59
|
return params?.map((param) => replaceWithNativeNullValue(param))
|
|
52
60
|
}
|
|
@@ -66,8 +74,8 @@ function buildJsQueryResult<Row extends QueryResultRow = never>({
|
|
|
66
74
|
return [key, null]
|
|
67
75
|
}
|
|
68
76
|
return [key, value]
|
|
69
|
-
})
|
|
70
|
-
)
|
|
77
|
+
}),
|
|
78
|
+
),
|
|
71
79
|
) as Row[]
|
|
72
80
|
}
|
|
73
81
|
|
|
@@ -3,42 +3,62 @@ import {
|
|
|
3
3
|
replaceWithNativeNullValue,
|
|
4
4
|
} from '../nullHandling'
|
|
5
5
|
import { HybridNitroSQLite } from '../nitro'
|
|
6
|
+
import {
|
|
7
|
+
queueOperationAsync,
|
|
8
|
+
startOperationSync,
|
|
9
|
+
throwIfDatabaseIsNotOpen,
|
|
10
|
+
} from '../DatabaseQueue'
|
|
6
11
|
import type {
|
|
7
12
|
NativeSQLiteQueryParams,
|
|
8
13
|
BatchQueryResult,
|
|
9
14
|
BatchQueryCommand,
|
|
10
15
|
NativeBatchQueryCommand,
|
|
11
16
|
} from '../types'
|
|
17
|
+
import NitroSQLiteError from '../NitroSQLiteError'
|
|
12
18
|
|
|
13
19
|
export function executeBatch(
|
|
14
20
|
dbName: string,
|
|
15
|
-
commands: BatchQueryCommand[]
|
|
21
|
+
commands: BatchQueryCommand[],
|
|
16
22
|
): BatchQueryResult {
|
|
23
|
+
throwIfDatabaseIsNotOpen(dbName)
|
|
24
|
+
|
|
17
25
|
const transformedCommands = isSimpleNullHandlingEnabled()
|
|
18
26
|
? toNativeBatchQueryCommands(commands)
|
|
19
27
|
: (commands as NativeBatchQueryCommand[])
|
|
20
28
|
|
|
21
|
-
|
|
22
|
-
|
|
29
|
+
try {
|
|
30
|
+
return startOperationSync(dbName, () =>
|
|
31
|
+
HybridNitroSQLite.executeBatch(dbName, transformedCommands),
|
|
32
|
+
)
|
|
33
|
+
} catch (error) {
|
|
34
|
+
throw NitroSQLiteError.fromError(error)
|
|
35
|
+
}
|
|
23
36
|
}
|
|
24
37
|
|
|
25
38
|
export async function executeBatchAsync(
|
|
26
39
|
dbName: string,
|
|
27
|
-
commands: BatchQueryCommand[]
|
|
40
|
+
commands: BatchQueryCommand[],
|
|
28
41
|
): Promise<BatchQueryResult> {
|
|
42
|
+
throwIfDatabaseIsNotOpen(dbName)
|
|
43
|
+
|
|
29
44
|
const transformedCommands = isSimpleNullHandlingEnabled()
|
|
30
45
|
? toNativeBatchQueryCommands(commands)
|
|
31
46
|
: (commands as NativeBatchQueryCommand[])
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
return queueOperationAsync(dbName, async () => {
|
|
49
|
+
try {
|
|
50
|
+
return await HybridNitroSQLite.executeBatchAsync(
|
|
51
|
+
dbName,
|
|
52
|
+
transformedCommands,
|
|
53
|
+
)
|
|
54
|
+
} catch (error) {
|
|
55
|
+
throw NitroSQLiteError.fromError(error)
|
|
56
|
+
}
|
|
57
|
+
})
|
|
38
58
|
}
|
|
39
59
|
|
|
40
60
|
function toNativeBatchQueryCommands(
|
|
41
|
-
commands: BatchQueryCommand[]
|
|
61
|
+
commands: BatchQueryCommand[],
|
|
42
62
|
): NativeBatchQueryCommand[] {
|
|
43
63
|
return commands.map((command) => {
|
|
44
64
|
const transformedParams = command.params?.map((param) => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HybridNitroSQLite } from '../nitro'
|
|
2
2
|
import { transaction } from './transaction'
|
|
3
3
|
import type {
|
|
4
4
|
BatchQueryCommand,
|
|
@@ -11,27 +11,41 @@ import type {
|
|
|
11
11
|
} from '../types'
|
|
12
12
|
import { execute, executeAsync } from './execute'
|
|
13
13
|
import { executeBatch, executeBatchAsync } from './executeBatch'
|
|
14
|
+
import NitroSQLiteError from '../NitroSQLiteError'
|
|
15
|
+
import { closeDatabaseQueue, openDatabaseQueue } from '../DatabaseQueue'
|
|
14
16
|
|
|
15
17
|
export function open(
|
|
16
|
-
options: NitroSQLiteConnectionOptions
|
|
18
|
+
options: NitroSQLiteConnectionOptions,
|
|
17
19
|
): NitroSQLiteConnection {
|
|
18
|
-
|
|
20
|
+
try {
|
|
21
|
+
HybridNitroSQLite.open(options.name, options.location)
|
|
22
|
+
openDatabaseQueue(options.name)
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw NitroSQLiteError.fromError(error)
|
|
25
|
+
}
|
|
19
26
|
|
|
20
27
|
return {
|
|
21
|
-
close: () =>
|
|
28
|
+
close: () => {
|
|
29
|
+
try {
|
|
30
|
+
HybridNitroSQLite.close(options.name)
|
|
31
|
+
closeDatabaseQueue(options.name)
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw NitroSQLiteError.fromError(error)
|
|
34
|
+
}
|
|
35
|
+
},
|
|
22
36
|
delete: () => HybridNitroSQLite.drop(options.name, options.location),
|
|
23
37
|
attach: (dbNameToAttach: string, alias: string, location?: string) =>
|
|
24
38
|
HybridNitroSQLite.attach(options.name, dbNameToAttach, alias, location),
|
|
25
39
|
detach: (alias: string) => HybridNitroSQLite.detach(options.name, alias),
|
|
26
|
-
transaction: (fn: (tx: Transaction) => Promise<
|
|
40
|
+
transaction: <Result = void>(fn: (tx: Transaction) => Promise<Result>) =>
|
|
27
41
|
transaction(options.name, fn),
|
|
28
42
|
execute: <Row extends QueryResultRow = never>(
|
|
29
43
|
query: string,
|
|
30
|
-
params?: SQLiteQueryParams
|
|
44
|
+
params?: SQLiteQueryParams,
|
|
31
45
|
): QueryResult<Row> => execute(options.name, query, params),
|
|
32
46
|
executeAsync: <Row extends QueryResultRow = never>(
|
|
33
47
|
query: string,
|
|
34
|
-
params?: SQLiteQueryParams
|
|
48
|
+
params?: SQLiteQueryParams,
|
|
35
49
|
): Promise<QueryResult<Row>> => executeAsync(options.name, query, params),
|
|
36
50
|
executeBatch: (commands: BatchQueryCommand[]) =>
|
|
37
51
|
executeBatch(options.name, commands),
|
|
@@ -43,17 +57,3 @@ export function open(
|
|
|
43
57
|
HybridNitroSQLite.loadFileAsync(options.name, location),
|
|
44
58
|
}
|
|
45
59
|
}
|
|
46
|
-
|
|
47
|
-
export function openDb(dbName: string, location?: string) {
|
|
48
|
-
HybridNitroSQLite.open(dbName, location)
|
|
49
|
-
|
|
50
|
-
locks[dbName] = {
|
|
51
|
-
queue: [],
|
|
52
|
-
inProgress: false,
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function close(dbName: string) {
|
|
57
|
-
HybridNitroSQLite.close(dbName)
|
|
58
|
-
delete locks[dbName]
|
|
59
|
-
}
|