Skip to content

Commit a75d6e5

Browse files
committed
Simplify TransactionImplementation.runWith
1 parent c9b70d1 commit a75d6e5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

packages/common/src/db/DBAdapter.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ export interface DBAdapter extends ConnectionPool, SqlExecutor, DBGetUtils {
202202
export function DBAdapterDefaultMixin<TBase extends new (...args: any[]) => ConnectionPool>(Base: TBase) {
203203
return class extends Base implements DBAdapter {
204204
readTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {
205-
return this.readLock((ctx) => TransactionImplementation.runWith(ctx, false, fn), options);
205+
return this.readLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
206206
}
207207

208208
writeTransaction<T>(fn: (tx: Transaction) => Promise<T>, options?: DBLockOptions): Promise<T> {
209-
return this.writeLock((ctx) => TransactionImplementation.runWith(ctx, true, fn), options);
209+
return this.writeLock((ctx) => TransactionImplementation.runWith(ctx, fn), options);
210210
}
211211

212212
getAll<T>(sql: string, parameters?: any[]): Promise<T[]> {
@@ -270,7 +270,7 @@ class BaseTransaction implements SqlExecutor {
270270
}
271271

272272
class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction) {
273-
static async runWith<T>(ctx: LockContext, isWrite: boolean, fn: (tx: Transaction) => Promise<T>): Promise<T> {
273+
static async runWith<T>(ctx: LockContext, fn: (tx: Transaction) => Promise<T>): Promise<T> {
274274
let tx = new TransactionImplementation(ctx);
275275

276276
// For write transactions, use BEGIN IMMEDIATE to immediately obtain a write lock on the database (instead of doing
@@ -279,7 +279,7 @@ class TransactionImplementation extends DBGetUtilsDefaultMixin(BaseTransaction)
279279
// the transaction). But if we have a "fake" read-only connection implemented through `pragma query_only = true`, we
280280
// can't use this trick because it would attempt to lock the connection. So there, we use a regular `BEGIN`
281281
// statement.
282-
const useBeginImmediate = isWrite || ctx.connectionType != 'queryOnly';
282+
const useBeginImmediate = ctx.connectionType != 'queryOnly';
283283

284284
try {
285285
await ctx.execute(useBeginImmediate ? 'BEGIN IMMEDIATE' : 'BEGIN');

0 commit comments

Comments
 (0)