Skip to main content

Overview

A Dialect is the glue between Kysely and the underlying database engine. Kysely provides built-in dialects for PostgreSQL, MySQL, SQLite, and MS SQL Server. Users can also implement custom dialects for other database engines.

Interface Definition

The Dialect interface is defined in src/dialect/dialect.ts:14 and requires the following methods:

Methods

createDriver
() => Driver
required
Creates a driver for the dialect. The driver handles the actual communication with the database, including connection pooling and query execution.
createQueryCompiler
() => QueryCompiler
required
Creates a query compiler for the dialect. The query compiler is responsible for transforming Kysely’s abstract query representation into SQL specific to the database engine.
createAdapter
() => DialectAdapter
required
Creates an adapter for the dialect. The adapter provides database-specific utilities for things like identifier quoting and data type mapping.
createIntrospector
(db: Kysely<any>) => DatabaseIntrospector
required
Creates a database introspector that can be used to get database metadata such as table names and column names. The db parameter never has any plugins installed - it’s created using Kysely.withoutPlugins.

Built-in Dialects

Kysely provides the following built-in dialects:

PostgreSQL

Uses the pg driver for PostgreSQL databases

MySQL

Uses the mysql2 driver for MySQL and MariaDB databases

SQLite

Uses the better-sqlite3 driver for SQLite databases

MS SQL Server

Uses the tedious driver for MS SQL Server databases

Creating a Custom Dialect

To create a custom dialect, implement the Dialect interface:
Then use it when creating a Kysely instance: