-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
73 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { FastifyPluginCallback } from "fastify"; | ||
import { | ||
Connection, | ||
ConnectionOptions, | ||
escape, | ||
format, | ||
Pool, | ||
PoolOptions, | ||
} from "mysql2"; | ||
import { | ||
Connection as PromiseConnection, | ||
Pool as PromisePool, | ||
} from "mysql2/promise"; | ||
|
||
type FastifyMysql = FastifyPluginCallback<fastifyMysql.MySQLOptions>; | ||
|
||
declare namespace fastifyMysql { | ||
|
||
// 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 MySQLOptions extends PoolOptions, ConnectionOptions { | ||
type?: ConnectionType; | ||
name?: string; | ||
promise?: boolean; | ||
connectionString?: string; | ||
} | ||
|
||
export const fastifyMysql: FastifyMysql | ||
export { fastifyMysql as default } | ||
} | ||
|
||
declare function fastifyMysql(...params: Parameters<FastifyMysql>): ReturnType<FastifyMysql> | ||
export = fastifyMysql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters