Skip to content

Commit 27840fb

Browse files
committed
Merge branch 'main' into fix/add-transaction-locks
2 parents 16a4a9c + aaca4e5 commit 27840fb

File tree

4 files changed

+38
-46
lines changed

4 files changed

+38
-46
lines changed

package/cpp/NitroSQLiteException.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
#include <exception>
44
#include <iostream>
55
#include <string>
6+
#include <optional>
7+
8+
const std::string NITRO_SQLITE_EXCEPTION_PREFIX = "[NativeNitroSQLiteException]";
69

7-
const std::string NITRO_SQLITE_EXCEPTION_PREFIX = "[NitroSQLiteException]";
810

911
enum NitroSQLiteExceptionType {
1012
UnknownError,
@@ -35,7 +37,7 @@ class NitroSQLiteException : public std::exception {
3537
explicit NitroSQLiteException(const std::string& message) : NitroSQLiteException(NitroSQLiteExceptionType::UnknownError, message) {}
3638
NitroSQLiteException(const NitroSQLiteExceptionType& type, const char* message) : NitroSQLiteException(type, std::string(message)) {}
3739
NitroSQLiteException(const NitroSQLiteExceptionType& type, const std::string& message)
38-
: _exceptionString(NITRO_SQLITE_EXCEPTION_PREFIX + " [" + typeToString(type) + "] " + message) {}
40+
: _exceptionString(NITRO_SQLITE_EXCEPTION_PREFIX + "[" + typeToString(type) + "] " + message) {}
3941

4042
private:
4143
const std::string _exceptionString;

package/src/NitroSQLiteError.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
const NITRO_SQLITE_ERROR_NAME = 'NitroSQLiteError' as const
2-
const NITRO_SQLITE_ERROR_PREFIX = '[NitroSQLite] ' as const
32

43
/**
54
* Custom error class for NitroSQLite operations
@@ -9,7 +8,6 @@ export default class NitroSQLiteError extends Error {
98
constructor(message: string, options?: ErrorOptions) {
109
super(message, options)
1110
this.name = NITRO_SQLITE_ERROR_NAME
12-
this.message = NITRO_SQLITE_ERROR_PREFIX + message
1311

1412
// Maintains proper prototype chain for instanceof checks
1513
Object.setPrototypeOf(this, NitroSQLiteError.prototype)

package/src/operations/executeBatch.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,16 @@ export async function executeBatchAsync(
4545
? toNativeBatchQueryCommands(commands)
4646
: (commands as NativeBatchQueryCommand[])
4747

48-
try {
49-
return queueOperationAsync(dbName, async () => {
50-
try {
51-
return await HybridNitroSQLite.executeBatchAsync(
52-
dbName,
53-
transformedCommands,
54-
)
55-
} catch (error) {
56-
throw NitroSQLiteError.fromError(error)
57-
}
58-
})
59-
} catch (error) {
60-
throw NitroSQLiteError.fromError(error)
61-
}
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+
})
6258
}
6359

6460
function toNativeBatchQueryCommands(

package/src/operations/transaction.ts

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,33 @@ export const transaction = async <Result = void>(
6161
return execute(dbName, 'ROLLBACK')
6262
}
6363

64-
try {
65-
return await queueOperationAsync(dbName, async () => {
66-
try {
67-
await executeAsync(
68-
dbName,
69-
isExclusive ? 'BEGIN EXCLUSIVE TRANSACTION' : 'BEGIN TRANSACTION',
70-
)
64+
return await queueOperationAsync(dbName, async () => {
65+
try {
66+
await executeAsync(
67+
dbName,
68+
isExclusive ? 'BEGIN EXCLUSIVE TRANSACTION' : 'BEGIN TRANSACTION',
69+
)
7170

72-
const result = await transactionCallback({
73-
commit,
74-
execute: executeOnTransaction,
75-
executeAsync: executeAsyncOnTransaction,
76-
rollback,
77-
})
71+
const result = await transactionCallback({
72+
commit,
73+
execute: executeOnTransaction,
74+
executeAsync: executeAsyncOnTransaction,
75+
rollback,
76+
})
7877

79-
if (!isFinalized) commit()
78+
if (!isFinalized) commit()
8079

81-
return result
82-
} catch (executionError) {
83-
if (!isFinalized) {
84-
try {
85-
rollback()
86-
} catch (rollbackError) {
87-
throw rollbackError
88-
}
89-
}
80+
return result
81+
} catch (executionError) {
82+
if (isFinalized) {
83+
throw NitroSQLiteError.fromError(executionError)
84+
}
9085

91-
throw executionError
86+
try {
87+
return rollback()
88+
} catch (rollbackError) {
89+
throw NitroSQLiteError.fromError(rollbackError)
9290
}
93-
})
94-
} catch (error) {
95-
throw NitroSQLiteError.fromError(error)
96-
}
91+
}
92+
})
9793
}

0 commit comments

Comments
 (0)