Skip to main content
Dialects are the bridge between Kysely and specific database engines. Each dialect handles database-specific query compilation, connection management, and feature support.

The Dialect Interface

All dialects implement the Dialect interface:

PostgreSQL Dialect

The PostgreSQL dialect uses the pg library.

Installation

Basic Configuration

Lazy Pool Initialization

Create the pool only when first used:

PostgreSQL-Specific Features

RETURNING clause:
JSON operations:

MySQL Dialect

The MySQL dialect uses the mysql2 library.

Installation

Basic Configuration

Lazy Pool Initialization

MySQL-Specific Features

LIMIT with OFFSET:

SQLite Dialect

The SQLite dialect uses the better-sqlite3 library.

Installation

Basic Configuration

In-Memory Database

Lazy Database Initialization

SQLite-Specific Features

AUTOINCREMENT:
RETURNING (SQLite 3.35.0+):

MS SQL Server Dialect

The MS SQL Server dialect uses the tedious library with tarn for connection pooling.

Installation

Basic Configuration

MS SQL-Specific Features

TOP clause:
OUTPUT clause:

Dialect Comparison

Connection Pooling

Each dialect handles connection pooling differently: PostgreSQL (pg):
MySQL (mysql2):
SQLite (better-sqlite3):
MS SQL Server (tedious + tarn):

Custom Dialects

You can create custom dialects by implementing the Dialect interface:

Best Practices

Always close your database connection when shutting down your application using await db.destroy().
Use lazy pool initialization in serverless environments to avoid creating connections at module load time.
SQLite’s better-sqlite3 is synchronous and single-threaded. Don’t use it for high-concurrency applications.
Different dialects support different SQL features. Always check the dialect-specific documentation when using advanced features.