Skip to content

Commit f982219

Browse files
committed
addressing review comments
1 parent 0fd9153 commit f982219

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

packages/runtime/src/client/crud/operations/base.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { clone } from '../../../utils/clone';
2222
import { enumerate } from '../../../utils/enumerate';
2323
import { extractFields, fieldsToSelectObject } from '../../../utils/object-utils';
2424
import { NUMERIC_FIELD_TYPES } from '../../constants';
25-
import type { CRUD } from '../../contract';
25+
import { TransactionIsolationLevel, type CRUD } from '../../contract';
2626
import type { FindArgs, SelectIncludeOmit, WhereInput } from '../../crud-types';
2727
import { InternalError, NotFoundError, QueryError } from '../../errors';
2828
import type { ToKysely } from '../../query-builder';
@@ -2089,7 +2089,7 @@ export abstract class BaseOperationHandler<Schema extends SchemaDef> {
20892089
} else {
20902090
// otherwise, create a new transaction and execute the callback
20912091
let txBuilder = this.kysely.transaction();
2092-
txBuilder = txBuilder.setIsolationLevel(isolationLevel ?? 'repeatable read');
2092+
txBuilder = txBuilder.setIsolationLevel(isolationLevel ?? TransactionIsolationLevel.RepeatableRead);
20932093
return txBuilder.execute(callback);
20942094
}
20952095
}

packages/runtime/src/client/executor/zenstack-query-executor.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
import { match } from 'ts-pattern';
2525
import type { GetModels, SchemaDef } from '../../schema';
2626
import { type ClientImpl } from '../client-impl';
27-
import type { ClientContract } from '../contract';
27+
import { TransactionIsolationLevel, type ClientContract } from '../contract';
2828
import { InternalError, QueryError } from '../errors';
2929
import type {
3030
AfterEntityMutationCallback,
@@ -213,7 +213,9 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
213213
return { result };
214214
} else {
215215
// if an on-the-fly tx is created, create one and wrap the query execution inside
216-
await this.driver.beginTransaction(connection, { isolationLevel: 'repeatable read' });
216+
await this.driver.beginTransaction(connection, {
217+
isolationLevel: TransactionIsolationLevel.ReadCommitted,
218+
});
217219
try {
218220
// execute the query inside the on-the-fly transaction
219221
const result = await connection.executeQuery<any>(compiled);
@@ -270,7 +272,9 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
270272
private hasPluginRequestingAfterMutationWithinTransaction(
271273
mutationInterceptionInfo: MutationInterceptionInfo<Schema>,
272274
) {
273-
return [...mutationInterceptionInfo.perPlugin.values()].some((info) => info.runAfterMutationWithinTransaction);
275+
return [...mutationInterceptionInfo.perPlugin.values()].some(
276+
(info) => info.intercept && info.runAfterMutationWithinTransaction,
277+
);
274278
}
275279

276280
private isMutationNode(queryNode: RootOperationNode): queryNode is MutationQueryNode {

0 commit comments

Comments
 (0)