
Kysely Has a Free Type-Safe SQL Query Builder — Like Knex but With Full TypeScript Autocomplete
The SQL Builder Problem Knex: great builder, returns any . Prisma: full ORM, can't write raw SQL easily. TypeORM: decorators, magic strings. Raw SQL: no autocomplete, no type checking. Kysely is a type-safe SQL query builder. Full TypeScript autocomplete for table names, column names, and result types. Zero runtime overhead. What Kysely Gives You Type-Safe Queries import { Kysely , PostgresDialect } from ' kysely ' ; interface Database { users : { id : number ; name : string ; email : string ; created_at : Date ; }; posts : { id : number ; title : string ; author_id : number ; }; } const db = new Kysely < Database > ({ dialect : new PostgresDialect ({ pool }) }); // Full autocomplete: table names, column names const users = await db . selectFrom ( ' users ' ) . select ([ ' id ' , ' name ' , ' email ' ]) . where ( ' email ' , ' like ' , ' %@company.com ' ) . orderBy ( ' created_at ' , ' desc ' ) . execute (); // users is typed as { id: number; name: string; email: string }[] Joins With
Continue reading on Dev.to Webdev
Opens in a new tab

