Skip to content

Commit

Permalink
get, getAll and getOptional should execute in a readLock
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney committed Nov 3, 2023
1 parent 7f7d857 commit 188f14f
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class RNQSDBAdapter extends BaseObserver<DBAdapterListener> implements DB
this.iterateListeners((cb) => cb.tablesUpdated?.(update));
});

const topLevelUtils = this.generateDBHelpers({ execute: this.baseDB.execute });
const topLevelUtils = this.generateDBHelpers({ execute: this.readOnlyExecute });
this.getAll = topLevelUtils.getAll;
this.getOptional = topLevelUtils.getOptional;
this.get = topLevelUtils.get;
Expand Down Expand Up @@ -55,6 +55,16 @@ export class RNQSDBAdapter extends BaseObserver<DBAdapterListener> implements DB
return this.baseDB.execute(query, params);
}

/**
* This provides a top-level read only execute method which is executed inside a read lock.
* This is necessary since the high level `execute` method uses a write-lock under
* the hood. Helper methods such as `get`, `getAll` and `getOptional` are read only,
* and should use this method.
*/
private readOnlyExecute(sql: string, params?: any[]) {
return this.readLock(ctx => ctx.execute(sql, params));
}

/**
* Adds DB get utils to lock contexts and transaction contexts
* @param tx
Expand Down

0 comments on commit 188f14f

Please sign in to comment.