Skip to main content

Quick Start

This guide will help you set up Kysely and execute your first type-safe SQL query in minutes.
1

Define Your Database Schema

Create TypeScript interfaces that describe your database structure. Kysely uses these to provide type-safety and autocompletion.
src/types.ts
For production applications, consider using kysely-codegen to automatically generate types from your database schema.
2

Create a Kysely Instance

Set up a Kysely instance with your database dialect and connection details.
src/database.ts
Keep secrets safe! Never hardcode credentials. Use environment variables or a secrets manager:
3

Write Your First Queries

Now you can start writing type-safe queries! Here are common operations:
Kysely is immutable! Query builder methods return a new query builder instance. Always re-assign the result:
4

Execute and Handle Results

Kysely provides several execution methods depending on your needs:

Complete Example

Here’s a complete working example using the user repository pattern from the Kysely source:
src/user.repository.ts

Next Steps

Migrations

Learn how to manage database schema changes

Advanced Queries

Explore joins, subqueries, CTEs, and more

API Reference

Browse the complete API documentation
Pro tip: Hover over any Kysely method in your IDE to see inline API documentation with examples!