Skip to content

Commit

Permalink
Add support for REPEATABLE READ isolation (requires server support) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans authored Feb 13, 2025
1 parent f42eadf commit 0c9d7ab
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/driver.rst
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ value specified below is the *default value* for that setting.
},
})
.withTransactionOptions({
isolation: IsolationLevel.Serializable, // only supported value
isolation: IsolationLevel.Serializable, // or .RepeatableRead if readonly
deferrable: false,
readonly: false,
});
Expand Down
1 change: 1 addition & 0 deletions packages/driver/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function defaultBackoff(attempt: number): number {

export enum IsolationLevel {
Serializable = "SERIALIZABLE",
RepeatableRead = "REPEATABLE READ",
}

export enum RetryCondition {
Expand Down
13 changes: 10 additions & 3 deletions packages/driver/test/transaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { type Client } from "../src/index.node";
import { IsolationLevel, TransactionOptions } from "../src/options";
import { sleep } from "../src/utils";
import Event from "../src/primitives/event";
import { getClient } from "./testbase";
import { getClient, getEdgeDBVersion } from "./testbase";

const typename = "TransactionTest";

Expand Down Expand Up @@ -82,17 +82,24 @@ test("transaction: regular 01", async () => {
});
}, 10_000);

const levels = [
undefined,
IsolationLevel.Serializable,
...(getEdgeDBVersion().major >= 6 ? [IsolationLevel.RepeatableRead] : []),
];

function* all_options(): Generator<
[IsolationLevel | undefined, boolean | undefined, boolean | undefined],
void,
void
> {
const levels = [undefined, IsolationLevel.Serializable];
const booleans = [undefined, true, false];
for (const isolation of levels) {
for (const readonly of booleans) {
for (const deferred of booleans) {
yield [isolation, readonly, deferred];
if (isolation != IsolationLevel.RepeatableRead || readonly) {
yield [isolation, readonly, deferred];
}
}
}
}
Expand Down

0 comments on commit 0c9d7ab

Please sign in to comment.