kysely-advanced-sql
Installation
SKILL.md
Kysely Advanced SQL
Write complex SQL queries using Kysely's type-safe query builder. Covers CTEs, window functions, CASE expressions, JSON operations, raw SQL, dynamic queries, and streaming.
Decision Tree
| Need | Solution |
|---|---|
| Reuse subquery result | CTE with .with() |
| Recursive hierarchy | .withRecursive() |
| Rank / running total | Window function with .over() |
| Conditional value | eb.case().when().then().else().end() |
| JSON aggregation | jsonArrayFrom / jsonObjectFrom (dialect helpers) |
| JSON traversal | eb.ref('col', '->').key('prop') |
| Custom SQL | sql tagged template |
| Dynamic column/table | db.dynamic.ref() / db.dynamic.table() |
| Large result set | .stream(chunkSize) |