---
title: "Conditions & Operators"
description: "Using Conditions & Operators in Tauri SQLite ORM."
canonical_url: "https://docs.ctrl-neo.dev/en/tauri-sqlite-orm/querying-data/conditions-and-operators"
---
# Conditions & Operators

> Using Conditions & Operators in Tauri SQLite ORM.

Condition operators are the functions you use to build filtering logic for your queries. They are passed to the
`.where()` clause of `select`, `update`, and `delete` statements to create powerful, type-safe SQL conditions. Each
operator function returns a special `{ sql, params }` object that the query builder uses to safely construct the final
query.

All operators are imported from the root of the `@type32/tauri-sqlite-orm` package.

```ts
import {eq, and, or, not, like, inArray /* etc. */} from '@type32/tauri-sqlite-orm';
```

## Logical Operators

These operators are used to combine multiple conditions.

<table>
<thead>
  <tr>
    <th>
      Operator
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Example Usage
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        <code>
          and(...conditions)
        </code>
      </strong>
    </td>
    
    <td>
      Combines multiple conditions with a logical <code>
        AND
      </code>
      
      .
    </td>
    
    <td>
      <code>
        where(and(eq(users._.columns.status, 'active'), gt(users._.columns.loginCount, 10)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          or(...conditions)
        </code>
      </strong>
    </td>
    
    <td>
      Combines multiple conditions with a logical <code>
        OR
      </code>
      
      .
    </td>
    
    <td>
      <code>
        where(or(eq(users._.columns.role, 'admin'), eq(users._.columns.role, 'owner')))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          not(condition)
        </code>
      </strong>
    </td>
    
    <td>
      Negates a single condition.
    </td>
    
    <td>
      <code>
        where(not(eq(users._.columns.status, 'banned')))
      </code>
    </td>
  </tr>
</tbody>
</table>

## Comparison Operators

These operators compare a column's value to a provided value.

<table>
<thead>
  <tr>
    <th>
      Operator
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Example Usage
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        <code>
          eq(column, value, alias?)
        </code>
      </strong>
    </td>
    
    <td>
      Equal (<code>
        =
      </code>
      
      ). The optional third argument is for table aliases, useful in <a href="../advanced-topics/joins">
        Joins
      </a>
      
      .
    </td>
    
    <td>
      <code>
        where(eq(users._.columns.id, 1))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          ne(column, value, alias?)
        </code>
      </strong>
    </td>
    
    <td>
      Not equal (<code>
        !=
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(ne(users._.columns.status, 'banned'))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          gt(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      Greater than (<code>
        >
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(gt(posts._.columns.viewCount, 1000))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          gte(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      Greater than or equal to (<code>
        >=
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(gte(users._.columns.age, 21))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          lt(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      Less than (<code>
        <
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(lt(products._.columns.stock, 5))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          lte(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      Less than or equal to (<code>
        <=
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(lte(tasks._.columns.priority, 2))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          between(column, min, max)
        </code>
      </strong>
    </td>
    
    <td>
      Between two values (<code>
        BETWEEN
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(between(products._.columns.price, 10, 50))
      </code>
    </td>
  </tr>
</tbody>
</table>

## Value Checking Operators

These operators are used for pattern matching, list containment, and `NULL` checks.

<table>
<thead>
  <tr>
    <th>
      Operator
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Example Usage
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        <code>
          like(column, pattern)
        </code>
      </strong>
    </td>
    
    <td>
      String pattern matching (<code>
        LIKE
      </code>
      
      ). Use <code>
        %
      </code>
      
       as a wildcard character.
    </td>
    
    <td>
      <code>
        where(like(users._.columns.email, '%@domain.com'))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          ilike(column, pattern)
        </code>
      </strong>
    </td>
    
    <td>
      Case-insensitive <code>
        LIKE
      </code>
      
       (uses <code>
        COLLATE NOCASE
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(ilike(users._.columns.name, '%john%'))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          startsWith(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      String starts with value (helper for <code>
        LIKE 'value%'
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(startsWith(users._.columns.email, 'admin'))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          endsWith(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      String ends with value (helper for <code>
        LIKE '%value'
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(endsWith(users._.columns.email, '@domain.com'))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          contains(column, value)
        </code>
      </strong>
    </td>
    
    <td>
      String contains value (helper for <code>
        LIKE '%value%'
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(contains(posts._.columns.title, 'TypeScript'))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          inArray(column, values)
        </code>
      </strong>
    </td>
    
    <td>
      Checks if a column's value is within an array of values (<code>
        IN
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(inArray(users._.columns.status, ['pending', 'reviewing']))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          notIn(column, values)
        </code>
      </strong>
    </td>
    
    <td>
      Checks if a column's value is NOT in an array (<code>
        NOT IN
      </code>
      
      ).
    </td>
    
    <td>
      <code>
        where(notIn(users._.columns.role, ['admin', 'owner']))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          isNull(column)
        </code>
      </strong>
    </td>
    
    <td>
      Checks if a column's value is <code>
        NULL
      </code>
      
      .
    </td>
    
    <td>
      <code>
        where(isNull(posts._.columns.publishedAt))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          isNotNull(column)
        </code>
      </strong>
    </td>
    
    <td>
      Checks if a column's value is <code>
        NOT NULL
      </code>
      
      .
    </td>
    
    <td>
      <code>
        where(isNotNull(posts._.columns.publishedAt))
      </code>
    </td>
  </tr>
</tbody>
</table>

## Subquery Operators

These operators work with subqueries. See [Advanced Topics](../6.advanced-topics/) for more on subqueries.

<table>
<thead>
  <tr>
    <th>
      Operator
    </th>
    
    <th>
      Description
    </th>
    
    <th>
      Example Usage
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        <code>
          exists(subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Checks if subquery returns any rows.
    </td>
    
    <td>
      <code>
        where(exists(subquery(...)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          notExists(subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Checks if subquery returns no rows.
    </td>
    
    <td>
      <code>
        where(notExists(subquery(...)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          inArray(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column value is in subquery results.
    </td>
    
    <td>
      <code>
        where(inArray(users._.columns.id, subquery(...)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          notIn(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column value not in subquery results.
    </td>
    
    <td>
      <code>
        where(notIn(users._.columns.id, subquery(...)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          eqSubquery(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column equals subquery result (scalar).
    </td>
    
    <td>
      <code>
        where(eqSubquery(posts._.columns.views, subq)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          gtSubquery(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column greater than subquery result.
    </td>
    
    <td>
      <code>
        where(gtSubquery(orders._.columns.total, avg)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          gteSubquery(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column greater than or equal to subquery.
    </td>
    
    <td>
      <code>
        where(gteSubquery(users._.columns.score, min)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          ltSubquery(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column less than subquery result.
    </td>
    
    <td>
      <code>
        where(ltSubquery(products._.columns.price, max)))
      </code>
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        <code>
          lteSubquery(column, subquery)
        </code>
      </strong>
    </td>
    
    <td>
      Column less than or equal to subquery.
    </td>
    
    <td>
      <code>
        where(lteSubquery(users._.columns.age, avg)))
      </code>
    </td>
  </tr>
</tbody>
</table>

## Combining Operators

The real power comes from composing these operators to create complex queries. Since `and()` and `or()` accept multiple
conditions, you can nest them to build precise filtering logic.

```ts
import {db} from '$lib/db';
import {users, posts} from '$lib/db/schema';
import {and, or, eq, isNull, gte, startsWith, between} from '@type32/tauri-sqlite-orm';

// Find all posts that are either unpublished OR have more than 100 likes
const popularOrUnpublishedPosts = await db.select(posts)
    .where(
        or(
            isNull(posts._.columns.publishedAt),
            gte(posts._.columns.likeCount, 100)
        )
    )
    .all();

// Find all active admin users
const activeAdmins = await db.select(users)
    .where(
        and(
            eq(users._.columns.status, 'active'),
            eq(users._.columns.role, 'admin')
        )
    )
    .all();

// Find products in price range with specific name pattern
const filteredProducts = await db.select(products)
    .where(
        and(
            between(products._.columns.price, 20, 100),
            startsWith(products._.columns.name, 'Premium')
        )
    )
    .all();
```


## Sitemap

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