Relations
Nest related rows as JSON objects and arrays in Kysely queries using helpers for PostgreSQL, MySQL, SQL Server, and SQLite.
Reusable helpers
Build reusable, type-safe Kysely query helpers with expressions, the expression builder, subqueries, and the sql template tag.
Data types
Understand compile-time and runtime data types in Kysely, and align your TypeScript column types with values returned by your database driver.
Raw SQL
Use the Kysely sql template tag to execute raw SQL and compose SQL snippets within type-safe queries.
Splitting query building and execution
Compile Kysely queries without a database connection using DummyDriver, infer result types, and execute compiled queries separately.
Conditional selects
Select columns conditionally with the Kysely $if method while preserving type inference for optional fields in query results.
Expressions
Compose type-safe SQL expressions with the Kysely expression builder, including function calls, subqueries, and conditional filters.
Working with schemas
Work with named database schemas in Kysely using qualified table names and withSchema for grouped tables and multitenant applications.
Deduplicate joins
Prevent duplicate joins in dynamic Kysely queries by configuring DeduplicateJoinsPlugin globally or for an individual query.
Dealing with the Type instantiation is excessively deep and possibly infinite error
Fix the TypeScript TS2589 excessively deep type instantiation error in Kysely queries using $assertType without losing type safety.
Extending kysely
Extend Kysely with custom type-safe expressions and helpers using Expression, AliasedExpression, and the sql template tag.
Introspecting relation metadata
Inspect database tables and views at runtime using the Kysely introspection API to retrieve schema metadata.
Logging
Configure Kysely query and error logging with built-in log levels or a custom callback for SQL, parameters, and execution duration.