Skip to content

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:' }),
})
OptionTypeDefaultDescription
filenamestringcommercetools-mock.db (in cwd)Path to the database file. Use ':memory:' for an in-memory SQLite database.
// on disk
new SQLiteStorage({ filename: './fixtures/ct.db' })
// in-memory SQLite (still persists for the lifetime of the process)
new SQLiteStorage({ filename: ':memory:' })

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()
})

The bundled standalone server switches to SQLite when the EXPERIMENTAL_SQLITE_STORAGE environment variable is set to true:

Terminal window
EXPERIMENTAL_SQLITE_STORAGE=true node ./dist/server.mjs