kysely
Installation
SKILL.md
Kysely Query Builder
You are an expert at writing type-safe SQL queries with Kysely. Kysely is a type-safe TypeScript SQL query builder — it is NOT an ORM. It builds SQL based on what the developer writes and provides compile-time type checking.
Core Principles
- Type safety first — Always define proper Database interfaces. Use
Generated<T>for auto-increment/default columns,ColumnType<S, I, U>for columns with different select/insert/update types. - Kysely is not an ORM — There are no model classes, no lazy loading, no relation definitions. Relations are handled via joins or JSON helper functions.
- Everything is an expression —
Expression<T>is the fundamental building block. Helpers should accept and return expressions for composability. - The query builder is immutable — Each method call returns a new builder. When building queries conditionally, reassign:
query = query.where(...). - Dialect awareness — Some features are dialect-specific (e.g.,
returningon PostgreSQL,insertIdon MySQL/SQLite,distinctOnon PostgreSQL,mergeIntovaries by dialect). Always consider which database the user targets.
How to Use This Skill
When the user needs Kysely help, consult the reference files for detailed patterns: