Overview
SQLite dialect that uses the better-sqlite3 library. This dialect is ideal for embedded databases, testing, and small-scale applications. Source:src/dialect/sqlite/sqlite-dialect.ts:38
Installation
Install the required peer dependency:Basic Usage
Configuration
SqliteDialectConfig
Source:src/dialect/sqlite/sqlite-dialect-config.ts:6
An SQLite Database instance or a function that returns one.If a function is provided, it’s called once when the first query is executed.See better-sqlite3 documentation for available database options.
Called once when the first query is executed. This is a Kysely-specific feature and does not come from the
better-sqlite3 module.Useful for setting up database-level configuration like PRAGMA statements.Database Options
When creating a better-sqlite3 Database instance, you can pass various options:Common Patterns
Enable Foreign Keys
SQLite requires foreign key constraints to be enabled per connection:Write-Ahead Logging (WAL)
Enable WAL mode for better concurrency:Performance Optimization
Optimize SQLite for better performance:In-Memory Database
Use in-memory databases for testing or temporary data:Read-Only Access
Open database in read-only mode:Testing
SQLite is excellent for testing due to its in-memory mode:Transactions
better-sqlite3 is synchronous and uses immediate transactions by default. Kysely handles this automatically:Backup and Restore
Use better-sqlite3’s backup API:Limitations
Related Types
SqliteDatabase
Source:src/dialect/sqlite/sqlite-dialect-config.ts:32
The subset of the better-sqlite3 Database interface that Kysely requires:
SqliteStatement
Source:src/dialect/sqlite/sqlite-dialect-config.ts:37