# Kysely > The most powerful type-safe SQL query builder for TypeScript - [Kysely](https://kysely.dev/index.md) ## docs ### category #### cte Short and simple examples of how to use Common Table Expressions (CTE) in queries. - [CTE](https://kysely.dev/docs/category/cte.md): Short and simple examples of how to use Common Table Expressions (CTE) in queries. #### delete Short and simple examples of how to write DELETE queries. - [DELETE](https://kysely.dev/docs/category/delete.md): Short and simple examples of how to write DELETE queries. #### examples Short and simple examples of how to use Kysely to achieve common tasks. - [Examples](https://kysely.dev/docs/category/examples.md): Short and simple examples of how to use Kysely to achieve common tasks. #### insert Short and simple examples of how to write INSERT queries. - [INSERT](https://kysely.dev/docs/category/insert.md): Short and simple examples of how to write INSERT queries. #### integrations Kysely integrations with other libraries, ORMs, and AI assistants. - [Integrations](https://kysely.dev/docs/category/integrations.md): Kysely integrations with other libraries, ORMs, and AI assistants. #### join Examples of queries that use JOINs. - [JOIN](https://kysely.dev/docs/category/join.md): Examples of queries that use JOINs. #### merge Short and simple examples of how to write MERGE queries. - [MERGE](https://kysely.dev/docs/category/merge.md): Short and simple examples of how to write MERGE queries. #### other-runtimes Use Kysely in browsers and Deno to build type-safe queries and compile SQL without a database connection. - [Other runtimes](https://kysely.dev/docs/category/other-runtimes.md): Use Kysely in browsers and Deno to build type-safe queries and compile SQL without a database connection. #### recipes Explore Kysely recipes for reusable helpers, expressions, nested relations, database schemas, logging, and advanced TypeScript types. - [Recipes](https://kysely.dev/docs/category/recipes.md): Explore Kysely recipes for reusable helpers, expressions, nested relations, database schemas, logging, and advanced TypeScript types. #### select Short and simple examples of using the SELECT methods. - [SELECT](https://kysely.dev/docs/category/select.md): Short and simple examples of using the SELECT methods. #### transactions Short and simple examples of how to use transactions. - [Transactions](https://kysely.dev/docs/category/transactions.md): Short and simple examples of how to use transactions. #### update Short and simple examples of how to write UPDATE queries. - [UPDATE](https://kysely.dev/docs/category/update.md): Short and simple examples of how to write UPDATE queries. #### where Short and simple examples of how to use the where method to add a WHERE statement. While most of the examples show a SELECT query, the where method works exactly the same in UPDATE and DELETE queries too. - [WHERE](https://kysely.dev/docs/category/where.md): Short and simple examples of how to use the where method to add a WHERE statement. While most of the examples show a SELECT query, the where method works exactly the same in UPDATE and DELETE queries too. ### dialects Find built-in and community Kysely dialects for PostgreSQL, MySQL, SQL Server, SQLite, and other databases. - [Dialects](https://kysely.dev/docs/dialects.md): Find built-in and community Kysely dialects for PostgreSQL, MySQL, SQL Server, SQLite, and other databases. ### examples #### cte - [Inserts, updates and deletions](https://kysely.dev/docs/examples/cte/inserts-updates-and-deletions.md): Some databases like postgres also allow you to run other queries than selects - [Simple selects](https://kysely.dev/docs/examples/cte/simple-selects.md): Common table expressions (CTE) are a great way to modularize complex queries. #### delete - [Single row](https://kysely.dev/docs/examples/delete/single-row.md): Delete a single row: #### insert - [Complex values](https://kysely.dev/docs/examples/insert/complex-values.md): In addition to primitives, the values can also be arbitrary expressions. - [Insert subquery](https://kysely.dev/docs/examples/insert/insert-subquery.md): You can create an INSERT INTO SELECT FROM query using the expression method. - [Multiple rows](https://kysely.dev/docs/examples/insert/multiple-rows.md): On dialects that support it (for example PostgreSQL) you can insert multiple - [Returning data](https://kysely.dev/docs/examples/insert/returning-data.md): On supported dialects like PostgreSQL you need to chain returning to the query to get - [Single row](https://kysely.dev/docs/examples/insert/single-row.md): Insert a single row: #### join - [Aliased inner join](https://kysely.dev/docs/examples/join/aliased-inner-join.md): You can give an alias for the joined table like this: - [Complex join](https://kysely.dev/docs/examples/join/complex-join.md): You can provide a function as the second argument to get a join - [Simple inner join](https://kysely.dev/docs/examples/join/simple-inner-join.md): Simple inner joins can be done by providing a table name and two columns to join: - [Subquery join](https://kysely.dev/docs/examples/join/subquery-join.md): You can join a subquery by providing two callbacks: #### merge - [Source row existence](https://kysely.dev/docs/examples/merge/source-row-existence.md): Update a target column based on the existence of a source row: - [Temporary changes table](https://kysely.dev/docs/examples/merge/temporary-changes-table.md): Merge new entries from a temporary changes table: #### select - [A single column](https://kysely.dev/docs/examples/select/a-single-column.md): Select a single column: - [Aliases](https://kysely.dev/docs/examples/select/aliases.md): You can give an alias for selections and tables by appending as the_alias to the name: - [All columns](https://kysely.dev/docs/examples/select/all-columns.md): The selectAll method generates SELECT *: - [All columns of a table](https://kysely.dev/docs/examples/select/all-columns-of-a-table.md): Select all columns of a table: - [Column with a table](https://kysely.dev/docs/examples/select/column-with-a-table.md): Select a single column and specify a table: - [Complex selections](https://kysely.dev/docs/examples/select/complex-selections.md): You can select arbitrary expression including subqueries and raw sql snippets. - [Distinct](https://kysely.dev/docs/examples/select/distinct.md): The API documentation is packed with examples. The API docs are hosted here, - [Distinct on](https://kysely.dev/docs/examples/select/distinct-on.md): The API documentation is packed with examples. The API docs are hosted here, - [Function calls](https://kysely.dev/docs/examples/select/function-calls.md): This example shows how to create function calls. These examples also work in any - [Generic find query](https://kysely.dev/docs/examples/select/generic-find-query.md): A generic type-safe helper function for finding a row by a column value: - [Multiple columns](https://kysely.dev/docs/examples/select/multiple-columns.md): Select multiple columns: - [Nested array](https://kysely.dev/docs/examples/select/nested-array.md): While kysely is not an ORM and it doesn't have the concept of relations, we do provide - [Nested object](https://kysely.dev/docs/examples/select/nested-object.md): While kysely is not an ORM and it doesn't have the concept of relations, we do provide - [Not null](https://kysely.dev/docs/examples/select/not-null.md): Sometimes you can be sure something's not null, but Kysely isn't able to infer #### transactions - [Controlled transaction](https://kysely.dev/docs/examples/transactions/controlled-transaction.md): A controlled transaction allows you to commit and rollback manually, execute - [Controlled transaction /w savepoints](https://kysely.dev/docs/examples/transactions/controlled-transaction-w-savepoints.md): A controlled transaction allows you to commit and rollback manually, execute - [Simple transaction](https://kysely.dev/docs/examples/transactions/simple-transaction.md): This example inserts two rows in a transaction. If an exception is thrown inside #### update - [Complex values](https://kysely.dev/docs/examples/update/complex-values.md): As always, you can provide a callback to the set method to get access - [MySQL joins](https://kysely.dev/docs/examples/update/my-sql-joins.md): MySQL allows you to join tables directly to the "main" table and update - [Single row](https://kysely.dev/docs/examples/update/single-row.md): Update a row in person table: #### where - [Complex where clause](https://kysely.dev/docs/examples/where/complex-where-clause.md): For complex where expressions you can pass in a single callback and - [Conditional where calls](https://kysely.dev/docs/examples/where/conditional-where-calls.md): You can add expressions conditionally like this: - [Object filter](https://kysely.dev/docs/examples/where/object-filter.md): You can use the and function to create a simple equality - [OR where](https://kysely.dev/docs/examples/where/or-where.md): To combine conditions using OR, you can use the expression builder. - [Simple where clause](https://kysely.dev/docs/examples/where/simple-where-clause.md): where method calls are combined with AND: - [Where in](https://kysely.dev/docs/examples/where/where-in.md): Find multiple items using a list of identifiers: ### execution Follow a Kysely query from type-safe query building through plugins, SQL compilation, database execution, and result transformation. - [Execution flow](https://kysely.dev/docs/execution.md): Follow a Kysely query from type-safe query building through plugins, SQL compilation, database execution, and result transformation. ### generating-types Generate Kysely database types from your database schema or Prisma models using tools such as kysely-codegen, prisma-kysely, and Kanel. - [Generating types](https://kysely.dev/docs/generating-types.md): Generate Kysely database types from your database schema or Prisma models using tools such as kysely-codegen, prisma-kysely, and Kanel. ### getting-started Get started with Kysely: install the package, define database types, configure a dialect, and write your first type-safe SQL queries. - [Getting started](https://kysely.dev/docs/getting-started.md): Get started with Kysely: install the package, define database types, configure a dialect, and write your first type-safe SQL queries. ### integrations #### llms Use the Kysely llms.txt and llms-full.txt documentation to give AI assistants and coding agents context for building SQL queries. - [LLMs](https://kysely.dev/docs/integrations/llms.md): Use the Kysely llms.txt and llms-full.txt documentation to give AI assistants and coding agents context for building SQL queries. #### supabase Use Kysely with Supabase by generating database types with the Supabase CLI and converting them with kysely-supabase. - [Supabase](https://kysely.dev/docs/integrations/supabase.md): Use Kysely with Supabase by generating database types with the Supabase CLI and converting them with kysely-supabase. ### intro Meet Kysely, a TypeScript SQL query builder with compile-time type safety, autocompletion, and inferred result types for joins and subqueries. - [Introduction](https://kysely.dev/docs/intro.md): Meet Kysely, a TypeScript SQL query builder with compile-time type safety, autocompletion, and inferred result types for joins and subqueries. ### migrations Write and run Kysely database migrations with up and down functions, migration providers, the Migrator API, and the kysely-ctl CLI. - [Migrations](https://kysely.dev/docs/migrations.md): Write and run Kysely database migrations with up and down functions, migration providers, the Migrator API, and the kysely-ctl CLI. ### playground Try Kysely in an interactive playground and share TypeScript query examples for questions, bug reports, and discussions. - [Playground](https://kysely.dev/docs/playground.md): Try Kysely in an interactive playground and share TypeScript query examples for questions, bug reports, and discussions. ### plugins Configure Kysely plugins for camelCase identifiers, duplicate joins, empty IN lists, and null comparisons. - [Plugin system](https://kysely.dev/docs/plugins.md): Configure Kysely plugins for camelCase identifiers, duplicate joins, empty IN lists, and null comparisons. ### recipes #### conditional-selects Select columns conditionally with the Kysely $if method while preserving type inference for optional fields in query results. - [Conditional selects](https://kysely.dev/docs/recipes/conditional-selects.md): Select columns conditionally with the Kysely $if method while preserving type inference for optional fields in query results. #### data-types Understand compile-time and runtime data types in Kysely, and align your TypeScript column types with values returned by your database driver. - [Data types](https://kysely.dev/docs/recipes/data-types.md): Understand compile-time and runtime data types in Kysely, and align your TypeScript column types with values returned by your database driver. #### deduplicate-joins Prevent duplicate joins in dynamic Kysely queries by configuring DeduplicateJoinsPlugin globally or for an individual query. - [Deduplicate joins](https://kysely.dev/docs/recipes/deduplicate-joins.md): Prevent duplicate joins in dynamic Kysely queries by configuring DeduplicateJoinsPlugin globally or for an individual query. #### excessively-deep-types Fix the TypeScript TS2589 excessively deep type instantiation error in Kysely queries using $assertType without losing type safety. - [Dealing with the Type instantiation is excessively deep and possibly infinite error](https://kysely.dev/docs/recipes/excessively-deep-types.md): Fix the TypeScript TS2589 excessively deep type instantiation error in Kysely queries using $assertType without losing type safety. #### expressions Compose type-safe SQL expressions with the Kysely expression builder, including function calls, subqueries, and conditional filters. - [Expressions](https://kysely.dev/docs/recipes/expressions.md): Compose type-safe SQL expressions with the Kysely expression builder, including function calls, subqueries, and conditional filters. #### extending-kysely Extend Kysely with custom type-safe expressions and helpers using Expression, AliasedExpression, and the sql template tag. - [Extending kysely](https://kysely.dev/docs/recipes/extending-kysely.md): 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. - [Introspecting relation metadata](https://kysely.dev/docs/recipes/introspecting-relation-metadata.md): 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. - [Logging](https://kysely.dev/docs/recipes/logging.md): Configure Kysely query and error logging with built-in log levels or a custom callback for SQL, parameters, and execution duration. #### raw-sql Use the Kysely sql template tag to execute raw SQL and compose SQL snippets within type-safe queries. - [Raw SQL](https://kysely.dev/docs/recipes/raw-sql.md): Use the Kysely sql template tag to execute raw SQL and compose SQL snippets within type-safe queries. #### relations Nest related rows as JSON objects and arrays in Kysely queries using helpers for PostgreSQL, MySQL, SQL Server, and SQLite. - [Relations](https://kysely.dev/docs/recipes/relations.md): 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. - [Reusable helpers](https://kysely.dev/docs/recipes/reusable-helpers.md): Build reusable, type-safe Kysely query helpers with expressions, the expression builder, subqueries, and the sql template tag. #### schemas Work with named database schemas in Kysely using qualified table names and withSchema for grouped tables and multitenant applications. - [Working with schemas](https://kysely.dev/docs/recipes/schemas.md): Work with named database schemas in Kysely using qualified table names and withSchema for grouped tables and multitenant applications. #### splitting-query-building-and-execution Compile Kysely queries without a database connection using DummyDriver, infer result types, and execute compiled queries separately. - [Splitting query building and execution](https://kysely.dev/docs/recipes/splitting-query-building-and-execution.md): Compile Kysely queries without a database connection using DummyDriver, infer result types, and execute compiled queries separately. ### runtimes #### browser Use Kysely in the browser to build type-safe queries and compile SQLite SQL with DummyDriver, without a database connection. - [Browser](https://kysely.dev/docs/runtimes/browser.md): Use Kysely in the browser to build type-safe queries and compile SQLite SQL with DummyDriver, without a database connection. #### deno Use Kysely on Deno to build type-safe queries and compile PostgreSQL SQL with DummyDriver, without a database connection. - [Running on Deno](https://kysely.dev/docs/runtimes/deno.md): Use Kysely on Deno to build type-safe queries and compile PostgreSQL SQL with DummyDriver, without a database connection.