| name | kysely-typescript |
| description | Type-safe SQL query building in TypeScript using Kysely. Use when writing or reviewing Kysely queries, schema types, migrations, raw SQL snippets, dynamic filters, conditional selects, transactions, or reusable query helpers. |
Kysely TypeScript Knowledge Hub
Use Kysely so TypeScript describes the SQL you are actually going to run.
Preserve inference by default; when a query must become dynamic or raw, make the
unsafe boundary small, typed, and reviewable.
Applicability Gate
Apply this skill when ANY of the following are true:
- The user asks to write or modify a database query using Kysely
- The user is designing a TypeScript schema for Kysely (the
Database interface)
- The user asks whether Kysely code is still type-safe
- The user uses raw SQL, dynamic identifiers, conditional selects, or reusable helpers
- The user encounters a type instantiation error in a Kysely query
- The user asks how to build dynamic queries, CTEs, or reusable query helpers
- The user needs to write a database migration using Kysely
Do NOT apply when:
- The task is generic TypeScript quality with no Kysely or SQL surface
- The task is ORM relation modeling; Kysely is a query builder, not an ORM
Routing Table
Procedure
- Identify the task type. What is the user trying to do with Kysely?
- Load the type-safety policy when it matters. Read
references/type-safety-first.md for
schema design, raw SQL, dynamic filters, conditional selects, reusable
helpers, type errors, or Kysely code review.
- Route to the right reference. Use the routing table above.
Read only the reference file(s) needed — do not load all.
- Apply the methodology. Follow the normative rules from the
loaded reference.
- Verify the boundary. Check that strict TypeScript accepts the query and
that declared column types match the runtime values returned by the driver.
Confirmation Policy
Do NOT execute destructive migrations or large schema changes without explicit user
confirmation. Present proposed code as diffs and wait for approval.