@fastify/postgres
Version:
Fastify PostgreSQL connection plugin
24 lines (15 loc) • 432 B
text/typescript
import fastify from 'fastify'
import { fastifyPostgres } from '../../../index'
const app = fastify()
app.register(fastifyPostgres, {
connectionString: 'postgres://user:password@host:port/db',
})
app.get('/calc', async () => {
const client = await app.pg.connect()
const sumResult = await client.query<{ sum: number }>('SELECT 2 + 2 as sum')
client.release()
return {
sum: sumResult.rows,
}
})
export { app }