Litestone guide / Introduction
Getting started
Install the package, write a model, and open a client over it. A database file that does not exist yet is created with the schema's tables.
bun add /litestone
bunx litestone init # writes schema.lite, litestone.config.js and migrations/
init writes one model to start from:
model User {
id Int
email String
name String?
createdAt DateTime (now())
deletedAt DateTime?
([email])
}
import { createClient } from '@frontierjs/litestone'
const db = await createClient({ path: './schema.lite', db: './development.db' })
const user = await db.user.create({ data: { email: 'alice@example.com', name: 'Alice' } })
const users = await db.user.findMany({ where: { name: 'Alice' }, orderBy: { createdAt: 'desc' }, limit: 20 })
await db.user.update({ where: { id: user.id }, data: { name: 'Alice Smith' } })
await db.user.remove({ where: { id: user.id } }) // soft, because of @@softDelete
if (users.length !== 1) throw new Error('expected one user')
What else it can do
bunx litestone migrate create <name>andmigrate applywrite and run migrationsbunx litestone studioopens a browser UI over your datadb: ':memory:'gives a throwaway database for testsschema: '...'takes an inline schema string instead of a pathlitestone.config.jsholds the default database path and other CLI settings
In depth: Getting started § Quick start