-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdriver.ts
43 lines (32 loc) · 1.21 KB
/
driver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import type {Driver, TransactionSettings} from 'kysely'
import {PostgresJSConnection} from './connection.js'
import type {PostgresJSDialectConfig} from './types.js'
import {freeze} from './utils.js'
export class PostgresJSDriver implements Driver {
readonly #config: PostgresJSDialectConfig
constructor(config: PostgresJSDialectConfig) {
this.#config = freeze({...config})
}
async init(): Promise<void> {
// noop
}
async acquireConnection(): Promise<PostgresJSConnection> {
const reservedConnection = await this.#config.postgres.reserve()
return new PostgresJSConnection(reservedConnection)
}
async beginTransaction(connection: PostgresJSConnection, settings: TransactionSettings): Promise<void> {
await connection.beginTransaction(settings)
}
async commitTransaction(connection: PostgresJSConnection): Promise<void> {
await connection.commitTransaction()
}
async rollbackTransaction(connection: PostgresJSConnection): Promise<void> {
await connection.rollbackTransaction()
}
async releaseConnection(connection: PostgresJSConnection): Promise<void> {
connection.releaseConnection()
}
async destroy(): Promise<void> {
await this.#config.postgres.end()
}
}