Skip to content

backend sqlite HowTo

GitHub Action edited this page Apr 21, 2026 · 1 revision

How To: Using @quatrain/backend-sqlite

This guide explains how to use the SQLite adapter for local development and testing.

Table of Contents

  1. In-Memory Database for Testing
  2. Persistent Local Storage

1. In-Memory Database for Testing

SQLite is excellent for automated testing because you can use an in-memory database that is completely destroyed when the process exits.

import { Backend } from '@quatrain/backend'
import { SqliteAdapter } from '@quatrain/backend-sqlite'

// Use ':memory:' as the filename
const memoryAdapter = new SqliteAdapter({
    config: {
        filename: ':memory:'
    }
})

Backend.addAdapter('default', memoryAdapter, true)

// In your test files:
// await myObject.save() // Saves instantly to RAM

2. Persistent Local Storage

For CLI tools or local data processing scripts, point the filename to a persistent path.

import { Backend } from '@quatrain/backend'
import { SqliteAdapter } from '@quatrain/backend-sqlite'
import path from 'path'

const dbPath = path.join(__dirname, '..', 'app.sqlite')

const localDb = new SqliteAdapter({
    config: {
        filename: dbPath
    }
})

Backend.addAdapter('default', localDb, true)

Clone this wiki locally