Gel automatically wraps every query you run in a transaction, defaulting to the strictest available isolation level. This guarantees data consistency and protects against common read/write anomalies. Recognizing that strictest isn't always necessary, we introduced the option to use the less strict, but still safe, RepeatableRead
level for read-only queries in version 6.0, later extending it to certain read-write queries in 6.5.
Now, we're simplifying things further. Both the JavaScript and Python clients now support PreferRepeatableRead
, a new virtual isolation level. When you select this, the client consults the server's analysis: can this specific query safely run at RepeatableRead
? If yes, the isolation level is automatically lowered, avoiding unnecessary locking and potential contention. If not, Gel defaults to the strictest level, maintaining safety. This means you no longer need to manually choose the optimal level; Gel handles it for you, often boosting throughput and reducing transaction retries.
To take advantage of this, ensure you're using Gel 6.5 or newer along with an updated client library. Then, set the isolation
transaction option to PreferRepeatableRead
in your client configuration.
import { createClient, IsolationLevel } from "gel";
import assert from "node:assert/strict";
const client = createClient()
.withTransactionOptions({
isolation: IsolationLevel.PreferRepeatableRead,
});
const result = await client.queryRequiredSingle<string>(
"select sys::get_transaction_isolation()",
);
assert(result === "REPEATABLE READ");
from gel import create_client, IsolationLevel
client = create_client()
.with_transaction_options(
isolation=IsolationLevel.PreferRepeatableRead,
)
result = client.query_required_single(
"select sys::get_transaction_isolation()",
)
assert result == "REPEATABLE READ"