SQLite storage
SQLiteStorage persists resources in a SQLite database using Node’s built-in
node:sqlite module (Node ≥ 22). It is
published under a separate entry point.
import { CommercetoolsMock } from '@labdigital/commercetools-mock'import { SQLiteStorage } from '@labdigital/commercetools-mock/sqlite'
const ctMock = new CommercetoolsMock({ defaultProjectKey: 'my-project', storage: new SQLiteStorage({ filename: ':memory:' }),})Options
Section titled “Options”| Option | Type | Default | Description |
|---|---|---|---|
filename | string | commercetools-mock.db (in cwd) | Path to the database file. Use ':memory:' for an in-memory SQLite database. |
// on disknew SQLiteStorage({ filename: './fixtures/ct.db' })
// in-memory SQLite (still persists for the lifetime of the process)new SQLiteStorage({ filename: ':memory:' })Closing the database
Section titled “Closing the database”SQLiteStorage holds a database connection. Call close() when you’re done to
release it — for example on process shutdown:
const storage = new SQLiteStorage()process.on('SIGINT', () => { storage.close() process.exit()})With the standalone server
Section titled “With the standalone server”The bundled standalone server
switches to SQLite when the EXPERIMENTAL_SQLITE_STORAGE environment variable is
set to true:
EXPERIMENTAL_SQLITE_STORAGE=true node ./dist/server.mjs