Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/react-native-nitro-sqlite/src/operations/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,8 @@ export function open(
),
detach: (alias: string) =>
runSyncOperation(() => HybridNitroSQLite.detach(connectionId, alias)),
transaction: async <Result = void>(
fn: (tx: Transaction) => Promise<Result>,
) => runOperation(() => transaction(connectionId, fn, false, queueKey)),
transaction: <Result = void>(fn: (tx: Transaction) => Promise<Result>) =>
runAsyncOperation(() => transaction(connectionId, fn, false, queueKey)),
execute: <Row extends QueryResultRow = never>(
query: string,
params?: SQLiteQueryParams,
Expand Down
12 changes: 6 additions & 6 deletions packages/react-native-nitro-sqlite/src/operations/transaction.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { queueOperationAsync, throwIfDatabaseIsNotOpen } from '../DatabaseQueue'
import { queueOperationAsync } from '../DatabaseQueue'
import type {
Transaction,
SQLiteQueryParams,
Expand Down Expand Up @@ -28,14 +28,12 @@ import type { DatabaseQueueKey } from '../DatabaseQueue'
* @returns The callback's result after the transaction finishes.
* @throws NitroSQLiteError if BEGIN, the callback, COMMIT, or ROLLBACK fails.
*/
export const transaction = async <Result = void>(
export const transaction = <Result = void>(
dbName: string,
transactionCallback: (tx: Transaction) => Promise<Result>,
isExclusive = false,
queueKey: DatabaseQueueKey = dbName,
) => {
throwIfDatabaseIsNotOpen(queueKey)

): Promise<Result> => {
const state: { current: TransactionState } = {
current: { kind: 'notStarted' },
}
Expand Down Expand Up @@ -143,7 +141,9 @@ export const transaction = async <Result = void>(
}
}

return await queueOperationAsync(queueKey, async () => {
// Only the callback below needs `async`; wrapping the queue too would add promise layers.
// The queue rejects when the database is not open.
return queueOperationAsync(queueKey, async () => {
try {
await executeAsyncNative(
dbName,
Expand Down
Loading