react-native-nitro-sqlite 9.1.11 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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/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,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { queueOperationAsync, throwIfDatabaseIsNotOpen } from '../DatabaseQueue'
|
|
2
2
|
import type {
|
|
3
3
|
QueryResult,
|
|
4
4
|
Transaction,
|
|
@@ -6,131 +6,88 @@ import type {
|
|
|
6
6
|
QueryResultRow,
|
|
7
7
|
} from '../types'
|
|
8
8
|
import { execute, executeAsync } from './execute'
|
|
9
|
+
import NitroSQLiteError from '../NitroSQLiteError'
|
|
9
10
|
|
|
10
|
-
export
|
|
11
|
-
/*
|
|
12
|
-
* The start function should not throw or return a promise because the
|
|
13
|
-
* queue just calls it and does not monitor for failures or completions.
|
|
14
|
-
*
|
|
15
|
-
* It should catch any errors and call the resolve or reject of the wrapping
|
|
16
|
-
* promise when complete.
|
|
17
|
-
*
|
|
18
|
-
* It should also automatically commit or rollback the transaction if needed
|
|
19
|
-
*/
|
|
20
|
-
start: () => void
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const transaction = (
|
|
11
|
+
export const transaction = async <Result = void>(
|
|
24
12
|
dbName: string,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
13
|
+
transactionCallback: (tx: Transaction) => Promise<Result>,
|
|
14
|
+
isExclusive = false,
|
|
15
|
+
) => {
|
|
16
|
+
throwIfDatabaseIsNotOpen(dbName)
|
|
29
17
|
|
|
30
|
-
let
|
|
18
|
+
let isFinished = false
|
|
31
19
|
|
|
32
|
-
|
|
33
|
-
const executeOnTransaction = <Data extends QueryResultRow = never>(
|
|
20
|
+
const executeOnTransaction = <Row extends QueryResultRow = never>(
|
|
34
21
|
query: string,
|
|
35
|
-
params?: SQLiteQueryParams
|
|
36
|
-
): QueryResult<
|
|
37
|
-
if (
|
|
38
|
-
throw
|
|
39
|
-
`
|
|
22
|
+
params?: SQLiteQueryParams,
|
|
23
|
+
): QueryResult<Row> => {
|
|
24
|
+
if (isFinished) {
|
|
25
|
+
throw new NitroSQLiteError(
|
|
26
|
+
`Cannot execute query on finalized transaction: ${dbName}`,
|
|
40
27
|
)
|
|
41
28
|
}
|
|
42
29
|
return execute(dbName, query, params)
|
|
43
30
|
}
|
|
44
31
|
|
|
45
|
-
const executeAsyncOnTransaction = <
|
|
32
|
+
const executeAsyncOnTransaction = <Row extends QueryResultRow = never>(
|
|
46
33
|
query: string,
|
|
47
|
-
params?: SQLiteQueryParams
|
|
48
|
-
): Promise<QueryResult<
|
|
49
|
-
if (
|
|
50
|
-
throw
|
|
51
|
-
`
|
|
34
|
+
params?: SQLiteQueryParams,
|
|
35
|
+
): Promise<QueryResult<Row>> => {
|
|
36
|
+
if (isFinished) {
|
|
37
|
+
throw new NitroSQLiteError(
|
|
38
|
+
`Cannot execute query on finalized transaction: ${dbName}`,
|
|
52
39
|
)
|
|
53
40
|
}
|
|
54
41
|
return executeAsync(dbName, query, params)
|
|
55
42
|
}
|
|
56
43
|
|
|
57
44
|
const commit = () => {
|
|
58
|
-
if (
|
|
59
|
-
throw
|
|
60
|
-
`
|
|
45
|
+
if (isFinished) {
|
|
46
|
+
throw new NitroSQLiteError(
|
|
47
|
+
`Cannot execute commit on finalized transaction: ${dbName}`,
|
|
61
48
|
)
|
|
62
49
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return result
|
|
50
|
+
isFinished = true
|
|
51
|
+
return execute(dbName, 'COMMIT')
|
|
66
52
|
}
|
|
67
53
|
|
|
68
54
|
const rollback = () => {
|
|
69
|
-
if (
|
|
70
|
-
throw
|
|
71
|
-
`
|
|
55
|
+
if (isFinished) {
|
|
56
|
+
throw new NitroSQLiteError(
|
|
57
|
+
`Cannot execute rollback on finalized transaction: ${dbName}`,
|
|
72
58
|
)
|
|
73
59
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return result
|
|
60
|
+
isFinished = true
|
|
61
|
+
return execute(dbName, 'ROLLBACK')
|
|
77
62
|
}
|
|
78
63
|
|
|
79
|
-
|
|
64
|
+
return await queueOperationAsync(dbName, async () => {
|
|
80
65
|
try {
|
|
81
|
-
await
|
|
66
|
+
await executeAsync(
|
|
67
|
+
dbName,
|
|
68
|
+
isExclusive ? 'BEGIN EXCLUSIVE TRANSACTION' : 'BEGIN TRANSACTION',
|
|
69
|
+
)
|
|
82
70
|
|
|
83
|
-
await
|
|
71
|
+
const result = await transactionCallback({
|
|
84
72
|
commit,
|
|
85
73
|
execute: executeOnTransaction,
|
|
86
74
|
executeAsync: executeAsyncOnTransaction,
|
|
87
75
|
rollback,
|
|
88
76
|
})
|
|
89
77
|
|
|
90
|
-
if (!
|
|
78
|
+
if (!isFinished) commit()
|
|
79
|
+
|
|
80
|
+
return result
|
|
91
81
|
} catch (executionError) {
|
|
92
|
-
if (!
|
|
82
|
+
if (!isFinished) {
|
|
93
83
|
try {
|
|
94
84
|
rollback()
|
|
95
85
|
} catch (rollbackError) {
|
|
96
|
-
throw rollbackError
|
|
86
|
+
throw NitroSQLiteError.fromError(rollbackError)
|
|
97
87
|
}
|
|
98
88
|
}
|
|
99
89
|
|
|
100
|
-
throw executionError
|
|
101
|
-
} finally {
|
|
102
|
-
locks[dbName]!.inProgress = false
|
|
103
|
-
isFinalized = false
|
|
104
|
-
startNextTransaction(dbName)
|
|
90
|
+
throw NitroSQLiteError.fromError(executionError)
|
|
105
91
|
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return new Promise((resolve, reject) => {
|
|
109
|
-
const tx: PendingTransaction = {
|
|
110
|
-
start: () => {
|
|
111
|
-
run().then(resolve).catch(reject)
|
|
112
|
-
},
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
locks[dbName]?.queue.push(tx)
|
|
116
|
-
startNextTransaction(dbName)
|
|
117
92
|
})
|
|
118
93
|
}
|
|
119
|
-
|
|
120
|
-
function startNextTransaction(dbName: string) {
|
|
121
|
-
if (locks[dbName] == null) throw Error(`Lock not found for db: ${dbName}`)
|
|
122
|
-
|
|
123
|
-
if (locks[dbName].inProgress) {
|
|
124
|
-
// Transaction is already in process bail out
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (locks[dbName].queue.length > 0) {
|
|
129
|
-
locks[dbName].inProgress = true
|
|
130
|
-
|
|
131
|
-
const tx = locks[dbName].queue.shift()!
|
|
132
|
-
setImmediate(() => {
|
|
133
|
-
tx.start()
|
|
134
|
-
})
|
|
135
|
-
}
|
|
136
|
-
}
|
|
@@ -16,26 +16,26 @@ export interface NitroSQLite
|
|
|
16
16
|
mainDbName: string,
|
|
17
17
|
dbNameToAttach: string,
|
|
18
18
|
alias: string,
|
|
19
|
-
location?: string
|
|
19
|
+
location?: string,
|
|
20
20
|
): void
|
|
21
21
|
detach(mainDbName: string, alias: string): void
|
|
22
22
|
execute(
|
|
23
23
|
dbName: string,
|
|
24
24
|
query: string,
|
|
25
|
-
params?: NativeSQLiteQueryParams
|
|
25
|
+
params?: NativeSQLiteQueryParams,
|
|
26
26
|
): NativeQueryResult
|
|
27
27
|
executeAsync(
|
|
28
28
|
dbName: string,
|
|
29
29
|
query: string,
|
|
30
|
-
params?: NativeSQLiteQueryParams
|
|
30
|
+
params?: NativeSQLiteQueryParams,
|
|
31
31
|
): Promise<NativeQueryResult>
|
|
32
32
|
executeBatch(
|
|
33
33
|
dbName: string,
|
|
34
|
-
commands: NativeBatchQueryCommand[]
|
|
34
|
+
commands: NativeBatchQueryCommand[],
|
|
35
35
|
): BatchQueryResult
|
|
36
36
|
executeBatchAsync(
|
|
37
37
|
dbName: string,
|
|
38
|
-
commands: NativeBatchQueryCommand[]
|
|
38
|
+
commands: NativeBatchQueryCommand[],
|
|
39
39
|
): Promise<BatchQueryResult>
|
|
40
40
|
loadFile(dbName: string, location: string): FileLoadResult
|
|
41
41
|
loadFileAsync(dbName: string, location: string): Promise<FileLoadResult>
|
package/src/typeORM.ts
CHANGED
|
@@ -18,7 +18,7 @@ interface TypeOrmNitroSQLiteConnection {
|
|
|
18
18
|
sql: string,
|
|
19
19
|
params: SQLiteQueryParams | undefined,
|
|
20
20
|
okExecute: (res: QueryResult<RowData>) => void,
|
|
21
|
-
failExecute: (msg: string) => void
|
|
21
|
+
failExecute: (msg: string) => void,
|
|
22
22
|
) => Promise<void>
|
|
23
23
|
transaction: (fn: (tx: Transaction) => Promise<void>) => Promise<void>
|
|
24
24
|
close: (okClose: () => void, failClose: (e: unknown) => void) => void
|
|
@@ -26,7 +26,7 @@ interface TypeOrmNitroSQLiteConnection {
|
|
|
26
26
|
dbNameToAttach: string,
|
|
27
27
|
alias: string,
|
|
28
28
|
location: string | undefined,
|
|
29
|
-
callback: () => void
|
|
29
|
+
callback: () => void,
|
|
30
30
|
) => void
|
|
31
31
|
detach: (alias: string, callback: () => void) => void
|
|
32
32
|
}
|
|
@@ -42,7 +42,7 @@ export const typeORMDriver = {
|
|
|
42
42
|
location?: string
|
|
43
43
|
},
|
|
44
44
|
ok: (db: TypeOrmNitroSQLiteConnection) => void,
|
|
45
|
-
fail: (msg: string) => void
|
|
45
|
+
fail: (msg: string) => void,
|
|
46
46
|
): TypeOrmNitroSQLiteConnection | null => {
|
|
47
47
|
try {
|
|
48
48
|
const db = Operations.open(options)
|
|
@@ -52,7 +52,7 @@ export const typeORMDriver = {
|
|
|
52
52
|
sql: string,
|
|
53
53
|
params: SQLiteQueryParams | undefined,
|
|
54
54
|
okExecute: (res: QueryResult<RowData>) => void,
|
|
55
|
-
failExecute: (msg: string) => void
|
|
55
|
+
failExecute: (msg: string) => void,
|
|
56
56
|
) => {
|
|
57
57
|
try {
|
|
58
58
|
const result = await db.executeAsync<RowData>(sql, params)
|
|
@@ -62,7 +62,7 @@ export const typeORMDriver = {
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
transaction: (
|
|
65
|
-
fn: (tx: Transaction) => Promise<void
|
|
65
|
+
fn: (tx: Transaction) => Promise<void>,
|
|
66
66
|
): Promise<void> => {
|
|
67
67
|
return db.transaction(fn)
|
|
68
68
|
},
|
|
@@ -78,7 +78,7 @@ export const typeORMDriver = {
|
|
|
78
78
|
dbNameToAttach: string,
|
|
79
79
|
alias: string,
|
|
80
80
|
location: string | undefined,
|
|
81
|
-
callback: () => void
|
|
81
|
+
callback: () => void,
|
|
82
82
|
) => {
|
|
83
83
|
db.attach(dbNameToAttach, alias, location)
|
|
84
84
|
callback()
|
package/src/types.ts
CHANGED
|
@@ -8,7 +8,9 @@ export interface NitroSQLiteConnection {
|
|
|
8
8
|
delete(): void
|
|
9
9
|
attach(dbNameToAttach: string, alias: string, location?: string): void
|
|
10
10
|
detach(alias: string): void
|
|
11
|
-
transaction
|
|
11
|
+
transaction: <Result = void>(
|
|
12
|
+
transactionCallback: (tx: Transaction) => Promise<Result>,
|
|
13
|
+
) => Promise<Result>
|
|
12
14
|
execute: ExecuteQuery
|
|
13
15
|
executeAsync: ExecuteAsyncQuery
|
|
14
16
|
executeBatch(commands: BatchQueryCommand[]): BatchQueryResult
|
|
@@ -67,12 +69,12 @@ export interface QueryResult<Row extends QueryResultRow = QueryResultRow> {
|
|
|
67
69
|
|
|
68
70
|
export type ExecuteQuery = <Row extends QueryResultRow = QueryResultRow>(
|
|
69
71
|
query: string,
|
|
70
|
-
params?: SQLiteQueryParams
|
|
72
|
+
params?: SQLiteQueryParams,
|
|
71
73
|
) => QueryResult<Row>
|
|
72
74
|
|
|
73
75
|
export type ExecuteAsyncQuery = <Row extends QueryResultRow = QueryResultRow>(
|
|
74
76
|
query: string,
|
|
75
|
-
params?: SQLiteQueryParams
|
|
77
|
+
params?: SQLiteQueryParams,
|
|
76
78
|
) => Promise<QueryResult<Row>>
|
|
77
79
|
|
|
78
80
|
export interface Transaction {
|