diff --git a/src/lib/postgres.ts b/src/lib/postgres.ts index 5a0921c..e8b8b26 100644 --- a/src/lib/postgres.ts +++ b/src/lib/postgres.ts @@ -10,6 +10,7 @@ import { Future } from '@/lib/Future'; class PostgresTransaction { public closed: boolean = false; + private started: boolean = false; constructor(private connection: PoolClient) {} @@ -60,6 +61,11 @@ class PostgresTransaction { query: string | QueryConfig, values?: string[] | undefined, ): Promise> { + if (!this.started) { + await this.connection.query('BEGIN ISOLATION LEVEL SERIALIZABLE'); + this.started = true; + } + if (this.closed) { throw new Error('Querying a closed connection'); }