Skip to main content

Kysely Query Builder

Build type-safe Kysely queries visually. Configure your table, select columns with optional aggregates, add WHERE conditions, JOINs, ORDER BY, and pagination — then get complete await db.selectFrom() code and TypeScript Database interface ready to drop in.

✓ SELECT / WHERE / JOIN ✓ Aggregate functions ✓ TypeScript DB interface ✓ Runs 100% in your browser

Frequently Asked Questions

What is Kysely?▼

Kysely is a type-safe TypeScript SQL query builder. Unlike ORMs, Kysely doesn't abstract away SQL — you write queries that look like SQL but get full TypeScript inference on column names, return types, and parameters. It works with PostgreSQL, MySQL, SQLite, and more. If your database schema is typed (via Database interface), Kysely will catch column name typos at compile time.

How does Kysely differ from Prisma or Drizzle?▼

Prisma generates a client from your schema and abstracts SQL behind a JavaScript API. Drizzle is also a type-safe query builder but uses a schema-declaration-first approach. Kysely is closer to raw SQL — you write .selectFrom().where().execute() chains, which makes it great for complex queries. Kysely also has a lighter runtime footprint than Prisma and doesn't require code generation.

How do I set up the Kysely database instance?▼

Install kysely and a dialect: npm install kysely pg (for PostgreSQL). Create a db.ts file: import { Kysely, PostgresDialect } from 'kysely'; import { Pool } from 'pg'; export const db = new Kysely<Database>({ dialect: new PostgresDialect({ pool: new Pool({ connectionString: process.env.DATABASE_URL }) }) }); The Database interface maps table names to their TypeScript row types — the generated types tab shows you the structure.

What is the Database interface?▼

The Database interface is the type-level schema Kysely uses to infer column names and return types. Each key is a table name, and the value is an interface describing the columns. Kysely uses Generated<T> for auto-increment columns, Selectable<T> / Insertable<T> / Updateable<T> utility types to derive variants for each use case. This tool generates the base table interface — add it to your central Database type.

What is the Generated<T> type for?▼

Generated<T> marks a column as auto-generated by the database (e.g. SERIAL / AUTO_INCREMENT id columns, default timestamps). When you insert a row, you don't provide these columns. Kysely's Insertable<T> utility automatically makes Generated<T> columns optional so TypeScript doesn't require them on insert while still returning them on select.

Can I use Kysely with Edge runtimes or serverless?▼

Yes — Kysely supports multiple dialects. For Cloudflare Workers and edge environments, use kysely-d1 (Cloudflare D1) or the neon-http dialect for Neon Postgres over HTTP. For PlanetScale, use kysely-planetscale. For local SQLite in Bun or Node.js, use the built-in SqliteDialect with better-sqlite3. The core query builder is dialect-agnostic.

Share this tool: X / Twitter LinkedIn
✓ 60,000+ developers use DevPlaybook ★★★★★ 4.8 / 5 on Gumroad ✓ MIT licensed · Instant download ✓ No login required

Related Products

on Gumroad

You Might Also Need

More Free Tools

Enjoying this tool? Get more like it.

Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.

DevPlaybook Pro 7 days free

Unlock AI-Powered Dev Tools

  • ⚡ AI Code Review, Doc Generator & SQL Builder
  • ⚡ All premium templates & early access
  • ⚡ Member discounts on Gumroad products
Start Free Trial →

$9/mo after trial · Cancel anytime

Want the full toolkit?

Get DevPlaybook Pro

Every template, guide, boilerplate, and automation script in one bundle. 13 premium products — grab them all at once and save big.

$79
$241 separately Save $162 (67% off)
Get DevPlaybook Pro — $79 →

MIT licensed · Instant download · No subscription

See what's included → Browse all deals →