brf/server/plugins/db.ts

18 lines
479 B
TypeScript

import type { FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import type { Kysely } from 'kysely'
import type { DB } from '../../shared/types.db.ts'
import fp from 'fastify-plugin'
const dbPlugin: FastifyPluginCallbackTypebox<{ kysely: Kysely<DB> }> = (fastify, { kysely }, done) => {
fastify.decorate('db', kysely)
fastify.addHook('onClose', () => kysely.destroy())
done()
}
export default fp(dbPlugin, {
fastify: '5.x',
name: 'dbPlugin',
})