---
title: "Introduction"
description: "Welcome to Tauri SQLite ORM - A Drizzle-like ORM for Tauri v2"
canonical_url: "https://docs.ctrl-neo.dev/en/tauri-sqlite-orm/introduction"
---
# Introduction

> Welcome to Tauri SQLite ORM - A Drizzle-like ORM for Tauri v2

## What is Tauri SQLite ORM?

A Drizzle-like TypeScript ORM tailored for Tauri v2's `@tauri-apps/plugin-sql` (SQLite). It provides a simple, type-safe query builder and migration tools to help you manage your database with ease.

## Key Features

### Type-Safe Query Building

Build SQL queries with TypeScript, ensuring type safety and autocompletion throughout your application.

```ts
const user = await db.select(users)
  .where(eq(users._.columns.email, 'john@example.com'))
  .first();

// user is fully typed! TypeScript knows all properties
user.id    // ✓ Autocomplete
user.name  // ✓ Type-safe
```

### Drizzle-Like Schema Definition

Define your database schema using a familiar, chainable API:

```ts
export const users = sqliteTable('users', {
  id: integer('id').primaryKey().autoincrement(),
  name: text('name').notNull(),
  email: text('email').notNull().unique(),
  createdAt: integer('created_at', { mode: 'timestamp' })
    .$defaultFn(() => new Date()),
});
```

### Powerful Relations

Define and query one-to-one, one-to-many, and many-to-many relationships:

```ts
const usersWithPosts = await db.select(users)
  .include({
    posts: {
      with: {  // ← Nested includes!
        comments: true,
        tags: true
      }
    }
  })
  .all();
```

### Advanced Query Capabilities

#### Utility Methods

```ts
// Check existence
const exists = await db.select(users).where(...).exists(); // boolean

// Count rows
const count = await db.select(users).where(...).count(); // number

// Get single column values
const emails = await db.select(users).pluck('email'); // string[]

// Easy pagination
const { data, totalPages } = await db.select(users).paginate(1, 20);
```

#### Rich Operator Set

```ts
// Comprehensive operators for every need
where(ne(users._.columns.status, 'banned'))
where(between(products._.columns.price, 10, 100))
where(notIn(users._.columns.id, [1, 2, 3]))
where(startsWith(users._.columns.email, 'admin'))
where(contains(posts._.columns.title, 'TypeScript'))
where(ilike(users._.columns.name, '%john%')) // Case-insensitive
```

#### Subqueries

```ts
// Use subqueries in WHERE clauses
const engineeringUsers = await db.select(users)
  .where(inArray(
    users._.columns.departmentId,
    subquery(db.select(departments).where(...))
  ))
  .all();
```

### Safety Features

#### WHERE Clause Validation

Prevent accidental mass updates/deletes:

```ts
// ❌ Throws error - prevents accidental data loss
await db.update(users).set({ isActive: false }).execute();

// ✅ Requires WHERE clause
await db.update(users)
  .set({ isActive: false })
  .where(eq(users._.columns.id, 123))
  .execute();
```

#### Atomic Operations

```ts
// Increment/decrement without race conditions
await db.update(posts)
  .increment('views')
  .where(eq(posts._.columns.id, postId))
  .execute();
```

#### Better Error Handling

```ts
try {
  await db.update(users).set({ name: 'Bob' }).execute();
} catch (error) {
  if (error instanceof MissingWhereClauseError) {
    // Handle specific error types
  }
}
```

### Developer Experience

#### Query Debugging

```ts
// Inspect SQL without executing
const { sql, params } = db.select(users).where(...).toSQL();
console.log('SQL:', sql);
console.log('Params:', params);
```

#### Automatic Migrations

```ts
// Keep database in sync with schema
await db.migrateIfDirty();
```

#### Full Type Inference

```ts
// InferSelectModel gives you the exact type
type User = InferSelectModel<typeof users>;

const user: User = await db.select(users).first();

// InferRelationalSelectModel for queries with .include()
const withPosts = { posts: true } as const;
type UserWithPosts = InferRelationalSelectModel<typeof users, typeof usersRelations, typeof withPosts>;
```

## Why Choose This ORM?

- **🎯 Type-Safe**: Full TypeScript support with complete type inference
- **🚀 Fast**: Lightweight layer over Tauri's SQL plugin with minimal overhead
- **🛡️ Safe**: Built-in protections against common mistakes
- **📦 Batteries-Included**: Relations, migrations, utilities all built-in
- **🔧 Flexible**: Use query builder OR raw SQL when needed
- **📚 Well-Documented**: Comprehensive guides and examples
- **🎨 Modern**: Drizzle-like API that feels familiar

## Quick Start

<code-group>

```bash [bun]
bun add @type32/tauri-sqlite-orm @tauri-apps/plugin-sql
```

```bash [pnpm]
pnpm add @type32/tauri-sqlite-orm @tauri-apps/plugin-sql
```

```bash [npm]
npm install @type32/tauri-sqlite-orm @tauri-apps/plugin-sql
```

</code-group>

See [Installation & Setup](https://docs.ctrl-neo.dev/2.installation-and-setup) for complete setup instructions.

## Next Steps

- [Installation & Setup](https://docs.ctrl-neo.dev/2.installation-and-setup) - Get started with installation
- [Your First Schema & Query](https://docs.ctrl-neo.dev/3.your-first-schema-and-query) - Quick start guide
- [Defining Schemas](https://docs.ctrl-neo.dev/4.core-concepts/1.defining-schemas) - Learn about schema definition
- [Working with Relations](https://docs.ctrl-neo.dev/6.advanced-topics/1.working-with-relations) - Master relationships

Welcome to Tauri SQLite ORM! 🎉


## Sitemap

See the full [sitemap](https://docs.ctrl-neo.dev/sitemap.md) for all pages.
