Skip to content

Commit

Permalink
Merge pull request #10 from depot/fix-transaction-await
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobwgillespie authored Dec 30, 2022
2 parents 71ec461 + f70406b commit d6e65b5
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,25 @@ class PlanetScaleConnection implements DatabaseConnection {

async beginTransaction() {
this.#transactionClient = this.#transactionClient ?? new PlanetScaleConnection(this.#config)
this.#transactionClient.#conn.execute('BEGIN')
await this.#transactionClient.#conn.execute('BEGIN')
}

async commitTransaction() {
if (!this.#transactionClient) throw new Error('No transaction to commit')
this.#transactionClient.#conn.execute('COMMIT')
this.#transactionClient = undefined
try {
await this.#transactionClient.#conn.execute('COMMIT')
} finally {
this.#transactionClient = undefined
}
}

async rollbackTransaction() {
if (!this.#transactionClient) throw new Error('No transaction to rollback')
this.#transactionClient.#conn.execute('ROLLBACK')
this.#transactionClient = undefined
try {
await this.#transactionClient.#conn.execute('ROLLBACK')
} finally {
this.#transactionClient = undefined
}
}

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

0 comments on commit d6e65b5

Please sign in to comment.