import { FastifyPluginCallback } from 'fastify' import * as Pg from 'pg' declare module 'fastify' { export interface FastifyInstance { pg: fastifyPostgres.PostgresDb & Record; } export interface FastifyRequest { pg?: Pg.PoolClient; } export interface RouteShorthandOptions { pg?: fastifyPostgres.FastifyPostgresRouteOptions; } } type FastifyPostgres = FastifyPluginCallback declare namespace fastifyPostgres { export type PostgresDb = { pool: Pg.Pool; Client: Pg.Client; query: Pg.Pool['query']; connect: Pg.Pool['connect']; transact: typeof transact; } export type FastifyPostgresRouteOptions = { transact: boolean | string; } export type PostgresPluginOptions = { /** * Custom pg */ pg?: typeof Pg; /** * Use pg-native */ native?: boolean; /** * Instance name of fastify-postgres */ name?: string; } & Pg.PoolConfig export function transact ( fn: (client: Pg.PoolClient) => Promise ): Promise export function transact ( fn: (client: Pg.PoolClient) => Promise, cb: (error: Error | null, result?: TResult) => void ): void export const fastifyPostgres: FastifyPostgres export { fastifyPostgres as default } } declare function fastifyPostgres (...params: Parameters): ReturnType export = fastifyPostgres