---
title: "API Reference"
description: "Quick reference for all ORM methods and functions"
canonical_url: "https://docs.ctrl-neo.dev/en/tauri-sqlite-orm/api-reference"
---
# API Reference

> Quick reference for all ORM methods and functions

## ORM Instance Methods

### Query Builders

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Returns
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        db.select(table, columns?)
      </code>
    </td>
    
    <td>
      <code>
        SelectQueryBuilder
      </code>
    </td>
    
    <td>
      Start a SELECT query
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.insert(table)
      </code>
    </td>
    
    <td>
      <code>
        InsertQueryBuilder
      </code>
    </td>
    
    <td>
      Start an INSERT query
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.update(table)
      </code>
    </td>
    
    <td>
      <code>
        UpdateQueryBuilder
      </code>
    </td>
    
    <td>
      Start an UPDATE query
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.delete(table)
      </code>
    </td>
    
    <td>
      <code>
        DeleteQueryBuilder
      </code>
    </td>
    
    <td>
      Start a DELETE query
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.upsert(table, data, conflictTarget)
      </code>
    </td>
    
    <td>
      <code>
        Promise
      </code>
    </td>
    
    <td>
      Insert or update on conflict
    </td>
  </tr>
</tbody>
</table>

### Utilities

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Returns
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        db.transaction(callback)
      </code>
    </td>
    
    <td>
      <code>
        Promise<T>
      </code>
    </td>
    
    <td>
      Execute operations in a transaction
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.migrate(options?)
      </code>
    </td>
    
    <td>
      <code>
        Promise<void>
      </code>
    </td>
    
    <td>
      Run database migrations
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.migrateIfDirty()
      </code>
    </td>
    
    <td>
      <code>
        Promise<boolean>
      </code>
    </td>
    
    <td>
      Run migrations only if schema changed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.isSchemaDirty()
      </code>
    </td>
    
    <td>
      <code>
        Promise<{dirty, current, stored}>
      </code>
    </td>
    
    <td>
      Check if schema has changed
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        db.$with(alias)
      </code>
    </td>
    
    <td>
      <code>
        WithQueryBuilder
      </code>
    </td>
    
    <td>
      Start a CTE (Common Table Expression)
    </td>
  </tr>
</tbody>
</table>

## SelectQueryBuilder Methods

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Returns
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        .where(condition)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Filter results with a condition
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .orderBy(column, direction?)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Sort results (ASC or DESC)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .limit(count)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Limit number of results
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .offset(count)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Skip first N results
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .distinct()
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Return only distinct rows
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .groupBy(...columns)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Group results by columns
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .having(condition)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Filter grouped results
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .leftJoin(table, condition, alias)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Add a LEFT JOIN
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .innerJoin(table, condition, alias)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Add an INNER JOIN
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .include(relations)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Load relations
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .all()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T[]>
      </code>
    </td>
    
    <td>
      Execute and return all rows
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .get()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T | undefined>
      </code>
    </td>
    
    <td>
      Execute and return first row
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .first()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T | undefined>
      </code>
    </td>
    
    <td>
      Alias for <code>
        .get()
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .exists()
      </code>
    </td>
    
    <td>
      <code>
        Promise<boolean>
      </code>
    </td>
    
    <td>
      Check if any rows exist
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .count()
      </code>
    </td>
    
    <td>
      <code>
        Promise<number>
      </code>
    </td>
    
    <td>
      Count matching rows
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .pluck(column)
      </code>
    </td>
    
    <td>
      <code>
        Promise<T[]>
      </code>
    </td>
    
    <td>
      Get array of single column values
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .paginate(page, pageSize)
      </code>
    </td>
    
    <td>
      <code>
        Promise<PaginationResult>
      </code>
    </td>
    
    <td>
      Get paginated results
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .toSQL()
      </code>
    </td>
    
    <td>
      <code>
        {sql, params}
      </code>
    </td>
    
    <td>
      Get SQL without executing
    </td>
  </tr>
</tbody>
</table>

## InsertQueryBuilder Methods

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Returns
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        .values(data)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Set data to insert (single object or array)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returning(...columns)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Return specific columns after insert
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returningAll()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T[]>
      </code>
    </td>
    
    <td>
      Return all columns after insert (array)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returningFirst()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T | undefined>
      </code>
    </td>
    
    <td>
      Return first inserted record (single object)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .onConflictDoNothing(target?)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Ignore conflicts
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .onConflictDoUpdate(config)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Update on conflict (upsert)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .execute()
      </code>
    </td>
    
    <td>
      <code>
        Promise<Result>
      </code>
    </td>
    
    <td>
      Execute the insert
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .toSQL()
      </code>
    </td>
    
    <td>
      <code>
        {sql, params}
      </code>
    </td>
    
    <td>
      Get SQL without executing
    </td>
  </tr>
</tbody>
</table>

## UpdateQueryBuilder Methods

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Returns
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        .set(data)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Set column values to update
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .where(condition)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Filter which rows to update (required!)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .increment(column, value?)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Atomically increment a column
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .decrement(column, value?)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Atomically decrement a column
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .allowGlobalOperation()
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Allow UPDATE without WHERE clause
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returning(...columns)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Return specific columns after update
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returningAll()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T[]>
      </code>
    </td>
    
    <td>
      Return all columns after update (array)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returningFirst()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T | undefined>
      </code>
    </td>
    
    <td>
      Return first updated record (single object)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .execute()
      </code>
    </td>
    
    <td>
      <code>
        Promise<Result>
      </code>
    </td>
    
    <td>
      Execute the update
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .toSQL()
      </code>
    </td>
    
    <td>
      <code>
        {sql, params}
      </code>
    </td>
    
    <td>
      Get SQL without executing
    </td>
  </tr>
</tbody>
</table>

## DeleteQueryBuilder Methods

<table>
<thead>
  <tr>
    <th>
      Method
    </th>
    
    <th>
      Returns
    </th>
    
    <th>
      Description
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        .where(condition)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Filter which rows to delete (required!)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .allowGlobalOperation()
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Allow DELETE without WHERE clause
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returning(...columns)
      </code>
    </td>
    
    <td>
      <code>
        this
      </code>
    </td>
    
    <td>
      Return specific columns from deleted rows
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returningAll()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T[]>
      </code>
    </td>
    
    <td>
      Return all columns from deleted rows (array)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .returningFirst()
      </code>
    </td>
    
    <td>
      <code>
        Promise<T | undefined>
      </code>
    </td>
    
    <td>
      Return first deleted record (single object)
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .execute()
      </code>
    </td>
    
    <td>
      <code>
        Promise<Result>
      </code>
    </td>
    
    <td>
      Execute the delete
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        .toSQL()
      </code>
    </td>
    
    <td>
      <code>
        {sql, params}
      </code>
    </td>
    
    <td>
      Get SQL without executing
    </td>
  </tr>
</tbody>
</table>

## Operators

### Comparison

- `eq(column, value, alias?)` - Equal
- `ne(column, value, alias?)` - Not equal
- `gt(column, value)` - Greater than
- `gte(column, value)` - Greater than or equal
- `lt(column, value)` - Less than
- `lte(column, value)` - Less than or equal
- `between(column, min, max)` - Between range

### Logical

- `and(...conditions)` - AND conditions
- `or(...conditions)` - OR conditions
- `not(condition)` - NOT condition

### String

- `like(column, pattern)` - LIKE pattern
- `ilike(column, pattern)` - Case-insensitive LIKE
- `startsWith(column, value)` - Starts with
- `endsWith(column, value)` - Ends with
- `contains(column, value)` - Contains substring

### Array/List

- `inArray(column, values | subquery)` - IN array or subquery
- `notIn(column, values | subquery)` - NOT IN array or subquery

### Null

- `isNull(column)` - IS NULL
- `isNotNull(column)` - IS NOT NULL

### Subquery

- `exists(subquery)` - EXISTS
- `notExists(subquery)` - NOT EXISTS
- `eqSubquery(column, subquery)` - Equal to subquery
- `gtSubquery(column, subquery)` - Greater than subquery
- `gteSubquery(column, subquery)` - Greater than or equal to subquery
- `ltSubquery(column, subquery)` - Less than subquery
- `lteSubquery(column, subquery)` - Less than or equal to subquery

## Column Helpers

- `text(name, config?)` - TEXT column
- `integer(name, config?)` - INTEGER column
- `real(name)` - REAL column
- `blob(name, config?)` - BLOB column
- `boolean(name)` - BOOLEAN column
- `numeric(name, config?)` - NUMERIC column
- `enumType(name, values)` - ENUM column

## Aggregate Functions

- `count(column?)` - COUNT
- `countDistinct(column)` - COUNT DISTINCT
- `sum(column)` - SUM
- `avg(column)` - AVG
- `min(column)` - MIN
- `max(column)` - MAX
- `groupConcat(column, separator?)` - GROUP_CONCAT (SQLite-specific)

## Subquery Helpers

- `subquery(query)` - Convert query to subquery
- `scalarSubquery(query)` - Scalar subquery for comparisons

## Utility Functions

- `asTauriDatabase(db)` - Type assertion for `@tauri-apps/plugin-sql` Database when TypeScript reports structural incompatibility. Use: `new TauriORM(asTauriDatabase(dbInstance), schema)`
- `sql` - Raw SQL template literal
- `asc(column)` - Ascending sort helper
- `desc(column)` - Descending sort helper
- `relations(table, callback)` - Define table relations (v1)
- `defineRelations(schema, callback)` - Define all relations in one place (v2, from/to, many-without-one, through)
- `defineRelationsPart(schema, callback)` - Define a part of relations for large schemas
- `through(column, junctionColumn, junctionTable)` - Many-to-many via junction table
- `optional: false` - One relation required at type level
- `where: (alias) => Condition` - Predefined filter on many relations

## Type Helpers

- `InferSelectModel<T>` - Infer SELECT result type
- `InferInsertModel<T>` - Infer INSERT data type
- `InferRelationalSelectModel<TTable, TRelations, TWith, TAllRelations?>` - Infer SELECT result type with relations from `.include(with)`

## Error Classes

- `TauriORMError` - Base error class
- `QueryBuilderError` - Query building errors
- `MissingWhereClauseError` - Missing WHERE clause
- `ValidationError` - Validation errors
- `InsertValidationError` - Insert validation errors
- `UpdateValidationError` - Update validation errors
- `ColumnNotFoundError` - Column not found
- `TableNotFoundError` - Table not found
- `MigrationError` - Migration errors
- `RelationError` - Relation errors


## Sitemap

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