Framework Guides
Fastify
Use KadakORM in Fastify routes with typed query patterns.
Fastify
Problem: fast APIs still need safe writes and bounded reads.
Solution: keep $limit on reads and validator checks on writes.
import Fastify from 'fastify'
import { connect, table } from '@shyk/kadak-orm'
const users = table('users', {
id: 'id',
email: 'email',
name: 'text',
})
const db = connect('postgres://postgres:postgres@localhost:5432/kadak_demo', { users })
const app = Fastify({ logger: true })
app.get('/users', async () => {
return db.users.findMany({ $limit: 50, $order: { id: 'desc' } })
})
app.post('/users', async (request, reply) => {
const parsed = users.insertValidator().safeParse(request.body)
if (!parsed.success) return reply.code(400).send(parsed.error.flatten())
const row = await db.users.insert(parsed.data)
return reply.code(201).send(row)
})
await app.listen({ port: 3000 })