Tauri SQLite ORM

API Reference

Quick reference for all ORM methods and functions

ORM Instance Methods

Query Builders

MethodReturnsDescription
db.select(table, columns?)SelectQueryBuilderStart a SELECT query
db.insert(table)InsertQueryBuilderStart an INSERT query
db.update(table)UpdateQueryBuilderStart an UPDATE query
db.delete(table)DeleteQueryBuilderStart a DELETE query
db.upsert(table, data, conflictTarget)PromiseInsert or update on conflict

Utilities

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

SelectQueryBuilder Methods

MethodReturnsDescription
.where(condition)thisFilter results with a condition
.orderBy(column, direction?)thisSort results (ASC or DESC)
.limit(count)thisLimit number of results
.offset(count)thisSkip first N results
.distinct()thisReturn only distinct rows
.groupBy(...columns)thisGroup results by columns
.having(condition)thisFilter grouped results
.leftJoin(table, condition, alias)thisAdd a LEFT JOIN
.innerJoin(table, condition, alias)thisAdd an INNER JOIN
.include(relations)thisLoad relations
.all()Promise<T[]>Execute and return all rows
.get()Promise<T | undefined>Execute and return first row
.first()Promise<T | undefined>Alias for .get()
.exists()Promise<boolean>Check if any rows exist
.count()Promise<number>Count matching rows
.pluck(column)Promise<T[]>Get array of single column values
.paginate(page, pageSize)Promise<PaginationResult>Get paginated results
.toSQL(){sql, params}Get SQL without executing

InsertQueryBuilder Methods

MethodReturnsDescription
.values(data)thisSet data to insert (single object or array)
.returning(...columns)thisReturn specific columns after insert
.returningAll()Promise<T[]>Return all columns after insert (array)
.returningFirst()Promise<T | undefined>Return first inserted record (single object)
.onConflictDoNothing(target?)thisIgnore conflicts
.onConflictDoUpdate(config)thisUpdate on conflict (upsert)
.execute()Promise<Result>Execute the insert
.toSQL(){sql, params}Get SQL without executing

UpdateQueryBuilder Methods

MethodReturnsDescription
.set(data)thisSet column values to update
.where(condition)thisFilter which rows to update (required!)
.increment(column, value?)thisAtomically increment a column
.decrement(column, value?)thisAtomically decrement a column
.allowGlobalOperation()thisAllow UPDATE without WHERE clause
.returning(...columns)thisReturn specific columns after update
.returningAll()Promise<T[]>Return all columns after update (array)
.returningFirst()Promise<T | undefined>Return first updated record (single object)
.execute()Promise<Result>Execute the update
.toSQL(){sql, params}Get SQL without executing

DeleteQueryBuilder Methods

MethodReturnsDescription
.where(condition)thisFilter which rows to delete (required!)
.allowGlobalOperation()thisAllow DELETE without WHERE clause
.returning(...columns)thisReturn specific columns from deleted rows
.returningAll()Promise<T[]>Return all columns from deleted rows (array)
.returningFirst()Promise<T | undefined>Return first deleted record (single object)
.execute()Promise<Result>Execute the delete
.toSQL(){sql, params}Get SQL without executing

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
Copyright © 2026