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
TheDialect interface is defined in src/dialect/dialect.ts:14 and requires the following methods:
Methods
() => Driver
required
Creates a driver for the dialect. The driver handles the actual communication with the database, including connection pooling and query execution.
() => 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.
() => DialectAdapter
required
Creates an adapter for the dialect. The adapter provides database-specific utilities for things like identifier quoting and data type mapping.
(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 databasesMySQL
Uses the
mysql2 driver for MySQL and MariaDB databasesSQLite
Uses the
better-sqlite3 driver for SQLite databasesMS SQL Server
Uses the
tedious driver for MS SQL Server databasesCreating a Custom Dialect
To create a custom dialect, implement theDialect interface: