Skip to content

Commit d6e65b5

Browse files
Merge pull request #10 from depot/fix-transaction-await
2 parents 71ec461 + f70406b commit d6e65b5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Diff for: src/index.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,25 @@ class PlanetScaleConnection implements DatabaseConnection {
139139

140140
async beginTransaction() {
141141
this.#transactionClient = this.#transactionClient ?? new PlanetScaleConnection(this.#config)
142-
this.#transactionClient.#conn.execute('BEGIN')
142+
await this.#transactionClient.#conn.execute('BEGIN')
143143
}
144144

145145
async commitTransaction() {
146146
if (!this.#transactionClient) throw new Error('No transaction to commit')
147-
this.#transactionClient.#conn.execute('COMMIT')
148-
this.#transactionClient = undefined
147+
try {
148+
await this.#transactionClient.#conn.execute('COMMIT')
149+
} finally {
150+
this.#transactionClient = undefined
151+
}
149152
}
150153

151154
async rollbackTransaction() {
152155
if (!this.#transactionClient) throw new Error('No transaction to rollback')
153-
this.#transactionClient.#conn.execute('ROLLBACK')
154-
this.#transactionClient = undefined
156+
try {
157+
await this.#transactionClient.#conn.execute('ROLLBACK')
158+
} finally {
159+
this.#transactionClient = undefined
160+
}
155161
}
156162

157163
async *streamQuery<O>(_compiledQuery: CompiledQuery, _chunkSize: number): AsyncIterableIterator<QueryResult<O>> {

0 commit comments

Comments
 (0)