Skip to content

Commit dad7b32

Browse files
authored
Make sure to start transactions in PostgreSQL connection (#29)
2 parents 22e513b + 7a9413e commit dad7b32

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/lib/postgres.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Future } from '@/lib/Future';
1010

1111
class PostgresTransaction {
1212
public closed: boolean = false;
13+
private started: boolean = false;
1314

1415
constructor(private connection: PoolClient) {}
1516

@@ -60,6 +61,11 @@ class PostgresTransaction {
6061
query: string | QueryConfig<string[]>,
6162
values?: string[] | undefined,
6263
): Promise<QueryResult<any>> {
64+
if (!this.started) {
65+
await this.connection.query('BEGIN ISOLATION LEVEL SERIALIZABLE');
66+
this.started = true;
67+
}
68+
6369
if (this.closed) {
6470
throw new Error('Querying a closed connection');
6571
}

0 commit comments

Comments
 (0)