-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
index.d.ts
84 lines (69 loc) · 2.39 KB
/
index.d.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { FastifyPluginCallback } from "fastify";
import {
Connection,
ConnectionOptions,
escape,
format,
Pool,
PoolOptions,
ProcedureCallPacket,
ResultSetHeader,
RowDataPacket,
} from "mysql2";
import {
Connection as PromiseConnection,
Pool as PromisePool,
} from "mysql2/promise";
type FastifyMysql = FastifyPluginCallback<fastifyMysql.FastifyMySQLOptions>;
declare namespace fastifyMysql {
type MySQLPoolConnection = MySQLPool | MySQLConnection | MySQLPromisePool | MySQLPromiseConnection;
export function isMySQLPool(obj: MySQLPoolConnection): obj is MySQLPool;
export function isMySQLPromisePool(obj: MySQLPoolConnection): obj is MySQLPromisePool;
export function isMySQLConnection(obj: MySQLPoolConnection): obj is MySQLConnection;
export function isMySQLPromiseConnection(obj: MySQLPoolConnection): obj is MySQLPromiseConnection;
// upstream package missed type
type escapeId = (val: any, forbidQualified?: boolean) => string;
interface BaseClient {
format: typeof format;
escape: typeof escape;
escapeId: escapeId;
}
export type MySQLConnection = Pick<Connection, "query" | "execute"> & {
connection: Connection;
} & BaseClient;
export type MySQLPool = Pick<Pool, "query" | "execute" | "getConnection"> & {
pool: Pool;
} & BaseClient;
export type MySQLPromiseConnection = Pick<
PromiseConnection,
"query" | "execute"
> & {
connection: PromiseConnection;
} & BaseClient;
export type MySQLPromisePool = Pick<
PromisePool,
"query" | "execute" | "getConnection"
> & {
pool: PromisePool;
} & BaseClient;
export type ConnectionType = "connection" | "pool";
export interface FastifyMySQLOptions extends PoolOptions, ConnectionOptions {
type?: ConnectionType;
name?: string;
promise?: boolean;
connectionString?: string;
}
export type MySQLProcedureCallPacket<
T = [MySQLRowDataPacket[], MySQLResultSetHeader] | MySQLResultSetHeader,
> = ProcedureCallPacket<T>
export type MySQLResultSetHeader = ResultSetHeader
export type MySQLRowDataPacket = RowDataPacket
export const fastifyMysql: FastifyMysql
export { fastifyMysql as default }
export {
ResultSetHeader,
RowDataPacket,
}
}
declare function fastifyMysql(...params: Parameters<FastifyMysql>): ReturnType<FastifyMysql>
export = fastifyMysql