| title | SQLite |
|---|---|
| sidebar_position | 1 |
To use Sequelize with SQLite, you need to install the @sequelize/sqlite dialect package:
npm i @sequelize/sqlite3Then use the SqliteDialect class as the dialect option in the Sequelize constructor:
import { Sequelize } from '@sequelize/core';
import { SqliteDialect } from '@sequelize/sqlite3';
const sequelize = new Sequelize({
dialect: SqliteDialect,
storage: 'sequelize.sqlite',
});import ConnectionOptions from './_connection-options.md';
The following options are accepted by the SQLite dialect:
| Option | Description |
|---|---|
storage |
Path to the SQLite database file. |
mode |
An integer bit flag that represents the mode to open the database connection with. The mode can be a union (using |) of OPEN_READONLY, OPEN_READWRITE, OPEN_CREATE, OPEN_FULLMUTEX, OPEN_URI, OPEN_SHAREDCACHE, OPEN_PRIVATECACHE, each of which are exposed by @sequelize/sqlite.Refer to the SQLite documentation to learn what each of these flags do. |
password |
The "PRAGMA KEY" password to use for the connection, if using plugins like sqlcipher. |
SQLite supports two types of temporary storages:
- Set
storageto an empty string to use a disk-based temporary storage. - Set
storageto':memory:'to use a memory-based temporary storage.
In both cases, the database will be destroyed when the connection is closed. As such, using temporary storage requires configuring the Connection Pool to keep a single connection open, using the following configuration:
const sequelize = new Sequelize({
dialect: SqliteDialect,
storage: ':memory:', // or ''
pool: { max: 1, idle: Infinity, maxUses: Infinity },
});The following options are also available for SQLite:
| Option | Description |
|---|---|
foreignKeys |
If set to false, SQLite will not enforce foreign keys. |