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.
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.
Related Products
on GumroadTypeScript Quick Reference Toolkit
5 practical reference files for TypeScript developers: cheatsheet, TS vs JS comparison, 20 utility types with real examples, tsconfig best practices template, and 15 common mistakes guide. Print it. Keep it on your desk.
Buy on Gumroad →Developer Cheat Sheet Bundle
10 print-ready cheat sheets for the tools developers use every day: Git, Docker, Linux CLI, SQL, Regex, HTTP Status codes, VS Code shortcuts, Bash scripting, jq/JSON, and Markdown.
Buy on Gumroad →DevToolkit Starter Kit
A ready-to-deploy developer tools website with 12 built-in tools. Astro + Preact + Tailwind. Deploy to Cloudflare Pages for free. Built-in SEO, dark mode, and ad-ready layout.
Buy on Gumroad →You Might Also Need
SQL Formatter & Beautifier
Format and beautify SQL queries online. Auto-indent SELECT, FROM, WHERE, JOIN clauses, uppercase keywords, and minify SQL to a single line. Supports MySQL, PostgreSQL, SQLite. Free, runs in browser —
Open free tool →
SQL Query Formatter
Format and prettify SQL queries online. Auto-indent SELECT, FROM, WHERE, JOIN clauses, uppercase or lowercase keywords, configurable indent size. Supports MySQL, PostgreSQL, SQLite. Runs in browser.
Open free tool →
SQL Query Formatter Pro
Advanced SQL formatter with MySQL, PostgreSQL, and SQLite dialect support. Syntax highlighting, configurable indent size and keyword case. Free, runs in your browser.
Open free tool →
More Free Tools
Related Articles
Drizzle ORM Complete Guide: TypeScript Database Toolkit 2026
Master Drizzle ORM 2026: schema definition, migrations, relations, RLS support, and Drizzle Studio. See how it compares to Prisma for TypeScript projects.
SQL Formatter Online: Beautify and Indent SQL Queries Instantly Free
Format messy SQL queries online for free. Beautify SELECT, JOIN, subquery, and CTE syntax with proper indentation. Supports PostgreSQL, MySQL, SQLite, and SQL Server.
PostgreSQL vs MySQL vs SQLite: Choosing the Right Database for Your Project
PostgreSQL vs MySQL vs SQLite: which database is best for your project? Compare performance, features, ease of use, scaling, and ideal use cases.
Database Indexing Strategies Every Developer Must Know
Master database indexing in 2026. Learn B-tree, hash, composite, partial, and covering indexes with practical SQL examples for PostgreSQL and MySQL.
PostgreSQL vs MySQL: Which to Choose in 2026?
Comprehensive comparison of PostgreSQL and MySQL in 2026. Performance, JSON support, replication, licensing, and a decision framework for choosing the right database for your project.
Enjoying this tool? Get more like it.
Weekly developer tool guides, productivity playbooks & AI tricks. Free. No spam.
Unlock AI-Powered Dev Tools
- ⚡ AI Code Review, Doc Generator & SQL Builder
- ⚡ All premium templates & early access
- ⚡ Member discounts on Gumroad products
$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.
MIT licensed · Instant download · No subscription
See what's included → Browse all deals →