🚧 VeloxKit is pre-release software. APIs may change before v1.0. Get started →
Documentation
APIs & Bindings
db (SQLite)

db Stable WINMACLNX

Built-in SQLite 3.45. Zero configuration — the database is created automatically in the app's data directory.

Requires capability: "db"

Capability Demo
velox.config.ts
export default defineConfig({
  capabilities: [
    "db",
  ],
})
db.query('SELECT * FROM notes')
[{ id: 1, title: "Meeting notes", body: "..." }]

Import

import { db } from 'veloxkit'

Queries

db.query(sql, params?)

Execute a SELECT and return all rows:

const notes = db.query('SELECT * FROM notes ORDER BY created_at DESC')
// → Note[]
 
const note = db.query('SELECT * FROM notes WHERE id = ?', [id])
// → Note[]  (use [0] for single row)

db.execute(sql, params?)

Execute INSERT, UPDATE, DELETE, or DDL:

db.execute(`
  CREATE TABLE IF NOT EXISTS notes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    body TEXT,
    created_at INTEGER DEFAULT (unixepoch())
  )
`)
 
const result = db.execute(
  'INSERT INTO notes (title, body) VALUES (?, ?)',
  ['My note', 'Content here']
)
console.log(result.lastInsertRowId)  // → 1
console.log(result.changes)          // → 1

db.transaction(fn)

Run multiple statements atomically:

db.transaction(() => {
  db.execute('DELETE FROM notes WHERE id = ?', [id])
  db.execute('INSERT INTO deleted_notes SELECT * FROM notes WHERE id = ?', [id])
})

If fn throws, the transaction is rolled back automatically.

Migrations

Manage schema versions:

import { db } from 'veloxkit'
 
db.migrate([
  // Version 1
  `CREATE TABLE notes (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    title TEXT NOT NULL,
    body TEXT,
    created_at INTEGER DEFAULT (unixepoch())
  )`,
  // Version 2
  `ALTER TABLE notes ADD COLUMN pinned INTEGER DEFAULT 0`,
])

db.migrate tracks which migrations have run in a _migrations table and only applies new ones.

Vector store

VeloxKit includes sqlite-vec for embedding storage:

const results = db.vectorSearch({
  table: 'embeddings',
  vector: embedding,
  limit: 5,
  threshold: 0.8,
})

See the Local AI guide for a complete example.

Using Drizzle ORM

VeloxKit is compatible with Drizzle ORM via the veloxkit-drizzle adapter:

import { drizzle } from 'veloxkit-drizzle'
import { notes } from './schema'
 
const db = drizzle()
const allNotes = await db.select().from(notes)

See the Database guide for a full Drizzle setup.

Database location

The database file is stored at:

macOS:   ~/Library/Application Support/<app-name>/db.sqlite
Windows: %APPDATA%\<app-name>\db.sqlite
Linux:   ~/.local/share/<app-name>/db.sqlite

Override with veloxkit.config.ts:

export default defineConfig({
  db: { path: './custom.sqlite' },  // relative to app data dir
})

All db calls are synchronous on the main thread by design. For heavy analytical queries, use db.queryAsync() which runs on a background thread.