Kadak
Framework Guides

TanStack Start

Use shared server functions with KadakORM and validator-driven writes.

TanStack Start

Problem: server functions need one source of truth for validation.

Solution: validate with table validators inside createServerFn handlers.

import { createServerFn } from '@tanstack/start'
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 })

export const listUsers = createServerFn({ method: 'GET' }).handler(async () => {
  return db.users.findMany({ $limit: 50, $order: { id: 'desc' } })
})

export const createUser = createServerFn({ method: 'POST' }).handler(async ({ data }) => {
  const parsed = users.insertValidator().safeParse(data)
  if (!parsed.success) throw new Error('Invalid payload')

  return db.users.insert(parsed.data)
})

On this page