Skip to content

Commit

Permalink
driver-adapters: fix Transaction.dispose for pg and neon (#4295)
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Sep 27, 2023
1 parent 802670c commit 743c426
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion query-engine/driver-adapters/js/adapter-neon/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prisma/adapter-neon",
"version": "0.4.1",
"version": "0.4.2",
"description": "Prisma's driver adapter for \"@neondatabase/serverless\"",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
8 changes: 7 additions & 1 deletion query-engine/driver-adapters/js/adapter-neon/src/neon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ class NeonWsQueryable<ClientT extends neon.Pool | neon.PoolClient> extends NeonQ
}

class NeonTransaction extends NeonWsQueryable<neon.PoolClient> implements Transaction {
finished = false

constructor(
client: neon.PoolClient,
readonly options: TransactionOptions,
Expand All @@ -90,19 +92,23 @@ class NeonTransaction extends NeonWsQueryable<neon.PoolClient> implements Transa
async commit(): Promise<Result<void>> {
debug(`[js::commit]`)

this.finished = true
this.client.release()
return Promise.resolve(ok(undefined))
}

async rollback(): Promise<Result<void>> {
debug(`[js::rollback]`)

this.finished = true
this.client.release()
return Promise.resolve(ok(undefined))
}

dispose(): Result<void> {
this.client.release()
if (!this.finished) {
this.client.release()
}
return ok(undefined)
}
}
Expand Down
2 changes: 1 addition & 1 deletion query-engine/driver-adapters/js/adapter-pg/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@prisma/adapter-pg",
"version": "0.4.1",
"version": "0.4.2",
"description": "Prisma's driver adapter for \"pg\"",
"main": "dist/index.js",
"module": "dist/index.mjs",
Expand Down
8 changes: 7 additions & 1 deletion query-engine/driver-adapters/js/adapter-pg/src/pg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,26 +76,32 @@ class PgQueryable<ClientT extends StdClient | TransactionClient> implements Quer
}

class PgTransaction extends PgQueryable<TransactionClient> implements Transaction {
finished = false

constructor(client: pg.PoolClient, readonly options: TransactionOptions) {
super(client)
}

async commit(): Promise<Result<void>> {
debug(`[js::commit]`)

this.finished = true
this.client.release()
return ok(undefined)
}

async rollback(): Promise<Result<void>> {
debug(`[js::rollback]`)

this.finished = true
this.client.release()
return ok(undefined)
}

dispose(): Result<void> {
this.client.release()
if (!this.finished) {
this.client.release()
}
return ok(undefined)
}
}
Expand Down

0 comments on commit 743c426

Please sign in to comment.