Quick Start
This guide gets you from zero to a running query. It uses SQLite in memory, so no database setup is required.
1. Install
Section titled “1. Install”pnpm add @mountsqli/core @mountsqli/driver-sqlite2. Define a table
Section titled “2. Define a table”import { defineTable, int, text } from "@mountsqli/core";
export const users = defineTable("users", { id: int().pk(), email: text().notNull(), age: int(),});
export type User = InferTable<typeof users>;3. Open the database
Section titled “3. Open the database”import { mountsqli } from "@mountsqli/core";
export const db = mountsqli({ driver: "sqlite", url: ":memory:", tables: [users],});4. Run a query
Section titled “4. Run a query”import { db, users } from "./db";
await db.from(users).insert({ email: "ada@example.com", age: 36 });
const adult = await db .from(users) .where("age", ">", 18) .orderBy("email", "asc") .findOne();
console.log(adult);// → { id: 1, email: "ada@example.com", age: 36 }That is it. The result is fully typed — adult is User | null.
What just happened?
Section titled “What just happened?”defineTablebuilt aTableDefwith phantom-typed columns.mountsqlicreated aDbwith a driver and your tables.- The builder produced a
QueryPlan, the dialect compiled it toSELECT ... WHERE "age" > ?, and the driver returned typed rows.
Real-world shape
Section titled “Real-world shape”In a real app you keep db.ts as the single source of truth and import db
wherever you query:
import { db, users } from "../db";
export async function listAdults() { return db.from(users).where("age", ">=", 18).all();}Best practices
Section titled “Best practices”- Put
defineTable+mountsqliin onedb.tsmodule. - Export
InferTable<typeof x>types alongside each table. - Use
:memory:for scripts and tests; use a file URL to persist.
Common mistakes
Section titled “Common mistakes”- Awaiting
mountsqli()— it is synchronous and returns aDbyou can use now. - Using
anyfor rows — letInferTabledo the work.
Related
Section titled “Related”- Your First Project — a fuller scaffold with config.
- Query Builder → Select — every read option.
- Schema → Defining Tables — column builders in depth.
