-
Notifications
You must be signed in to change notification settings - Fork 279
/
driver.ts
67 lines (57 loc) · 1.77 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { ArrayItemType } from '../util/type-utils.js'
import { DatabaseConnection } from './database-connection.js'
/**
* A Driver creates and releases {@link DatabaseConnection | database connections}
* and is also responsible for connection pooling (if the dialect supports pooling).
*/
export interface Driver {
/**
* Initializes the driver.
*
* After calling this method the driver should be usable and `acquireConnection` etc.
* methods should be callable.
*
* IMPORTANT: The underlying database engine driver (like [pg](https://node-postgres.com/))
* should be imported inside this function, not at the top of the driver file! This is
* important so that Kysely is usable without installing all database driver libraries
* it supports.
*/
init(): Promise<void>
/**
* Acquires a new connection from the pool.
*/
acquireConnection(): Promise<DatabaseConnection>
/**
* Begins a transaction.
*/
beginTransaction(
connection: DatabaseConnection,
settings: TransactionSettings
): Promise<void>
/**
* Commits a transaction.
*/
commitTransaction(connection: DatabaseConnection): Promise<void>
/**
* Rolls back a transaction.
*/
rollbackTransaction(connection: DatabaseConnection): Promise<void>
/**
* Releases a connection back to the pool.
*/
releaseConnection(connection: DatabaseConnection): Promise<void>
/**
* Destroys the driver and releases all resources.
*/
destroy(): Promise<void>
}
export interface TransactionSettings {
readonly isolationLevel?: IsolationLevel
}
export const TRANSACTION_ISOLATION_LEVELS = [
'read uncommitted',
'read committed',
'repeatable read',
'serializable',
] as const
export type IsolationLevel = ArrayItemType<typeof TRANSACTION_ISOLATION_LEVELS>