-
Notifications
You must be signed in to change notification settings - Fork 280
/
mysql-dialect-config.ts
66 lines (58 loc) · 1.68 KB
/
mysql-dialect-config.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
import { DatabaseConnection } from '../../driver/database-connection.js'
/**
* Config for the MySQL dialect.
*
* https://github.com/sidorares/node-mysql2#using-connection-pools
*/
export interface MysqlDialectConfig {
/**
* A mysql2 Pool instance or a function that returns one.
*
* If a function is provided, it's called once when the first query is executed.
*
* https://github.com/sidorares/node-mysql2#using-connection-pools
*/
pool: MysqlPool | (() => Promise<MysqlPool>)
/**
* Called once for each created connection.
*/
onCreateConnection?: (connection: DatabaseConnection) => Promise<void>
}
/**
* This interface is the subset of mysql2 driver's `Pool` class that
* kysely needs.
*
* We don't use the type from `mysql2` here to not have a dependency to it.
*
* https://github.com/sidorares/node-mysql2#using-connection-pools
*/
export interface MysqlPool {
getConnection(
callback: (error: unknown, connection: MysqlPoolConnection) => void
): void
end(callback: (error: unknown) => void): void
}
export interface MysqlPoolConnection {
query(
sql: string,
parameters: ReadonlyArray<unknown>
): { stream: <T>(options: MysqlStreamOptions) => MysqlStream<T> }
query(
sql: string,
parameters: ReadonlyArray<unknown>,
callback: (error: unknown, result: MysqlQueryResult) => void
): void
release(): void
}
export interface MysqlStreamOptions {
highWaterMark?: number
objectMode?: boolean
}
export interface MysqlStream<T> {
[Symbol.asyncIterator](): AsyncIterableIterator<T>
}
export interface MysqlOkPacket {
affectedRows: number
insertId: number
}
export type MysqlQueryResult = MysqlOkPacket | Record<string, unknown>[]