ORMs promise to hide SQL from you, but they often end up hiding the database itself — and then you fight the ORM instead of writing queries. Kysely takes the opposite approach: it is a type-safe SQL query builder. You write real SQL, in TypeScript, with full autocomplete and compile-time checks.
Here is a simple query:
import { Kysely , PostgresDialect } from 'kysely' ;
interface Database { users : { id : number ; name : string ; email : string ; created_at : Date } ; posts : { id : number ; author_id : number ; title : string } ; }
const db = new Kysely < Database > ( { dialect : new PostgresDialect ( { pool } ) } ) ;
const activeUsers = await db . selectFrom ( 'users' ) . select ( [ 'id' , 'name' , 'email' ] ) . where ( 'created_at' , '>' , new Date ( '2026-01-01' ) ) . orderBy ( 'created_at' , 'desc' ) . limit ( 10 ) . execute ( ) ;
Enter fullscreen mode
Exit fullscreen mode
If you mistype a column name, TypeScript tells you immediately.…