Tauri SQLite ORM

Installation & Setup

Follow these steps to integrate the ORM into your Tauri project.

Installation & Setup

Follow these steps to integrate the ORM into your Tauri project.

1. Install Packages

This library requires @tauri-apps/plugin-sql. You can install both using your preferred package manager.

bun add @type32/tauri-sqlite-orm @tauri-apps/plugin-sql

2. Initialize the ORM

Create an instance of the ORM in your frontend TypeScript code. It's best practice to do this in a dedicated file and export a singleton instance.

Create a file, for example src/lib/db/index.ts:

src/lib/db/index.ts
import Database from '@tauri-apps/plugin-sql'
import { TauriORM, asTauriDatabase } from '@type32/tauri-sqlite-orm'

// This is where you will define your tables and relations.
// We'll create this file in the next guide.
import * as schema from './schema'

// This will load or create a database file `main.db` in your
// app's sandboxed data directory.
const dbInstance = await Database.load('sqlite:main.db')

// Initialize the ORM with the database instance and schema.
// Passing the schema object enables automatic migrations and relation queries.
// Use asTauriDatabase() if TypeScript reports type incompatibility.
export const db = new TauriORM(asTauriDatabase(dbInstance), schema)
Type compatibility: If TypeScript reports that Database is not assignable to DatabaseLike, wrap the instance with asTauriDatabase(dbInstance). This is a type assertion helper—the ORM uses $1, $2, $3 placeholders compatible with @tauri-apps/plugin-sql.

Now you're all set! The db object is your main entry point for all database interactions. In the next section, we'll define a schema and run our first query.

Copyright © 2026