MCPcopy Create free account
hub / github.com/cameri/nostream / Transaction

Class Transaction

src/database/transaction.ts:6–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import { ITransaction } from '../@types/database'
5
6export class Transaction implements ITransaction {
7 private trx: Knex.Transaction<any, any[]>
8
9 public constructor(private readonly dbClient: DatabaseClient) {}
10
11 public async begin(): Promise<void> {
12 this.trx = await this.dbClient.transaction(null, { isolationLevel: 'serializable' })
13 }
14
15 public get transaction(): DatabaseTransaction {
16 if (!this.trx) {
17 throw new Error('Unable to get transaction: transaction not started.')
18 }
19 return this.trx
20 }
21
22 public async commit(): Promise<any[]> {
23 if (!this.trx) {
24 throw new Error('Unable to get transaction: transaction not started.')
25 }
26 return this.trx.commit()
27 }
28
29 public async rollback(): Promise<any[]> {
30 if (!this.trx) {
31 throw new Error('Unable to get transaction: transaction not started.')
32 }
33 return this.trx.rollback()
34 }
35}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected