Skip to content

Comparison Operators

UQL provide a comprehensive set of operators for comparing field values. These operators are context-aware, meaning they are typed according to the field they are applied to.

NameDescription
$eqEqual to.
$neNot equal to (null-safe: rows where the column is NULL still match when the value is not null).
$ltLess than.
$lteLess than or equal to.
$gtGreater than.
$gteGreater than or equal to.
$startsWithStarts with (case-sensitive).
$istartsWithStarts with (case-insensitive).
$endsWithEnds with (case-sensitive).
$iendsWithEnds with (case-insensitive).
$includesContains substring (case-sensitive).
$iincludesContains substring (case-insensitive).
$inValue matches any in a given array.
$ninValue does not match any in a given array.
$betweenValue is between two bounds (inclusive). E.g. { age: { $between: [18, 65] } }.
$isNullField is null. E.g. { deletedAt: { $isNull: true } }.
$isNotNullField is not null. E.g. { email: { $isNotNull: true } }.
$allArray contains all specified values. E.g. { tags: { $all: ['ts', 'orm'] } }.
$sizeArray has the specified length. Accepts a number for exact match ({ tags: { $size: 3 } }) or comparison operators ({ tags: { $size: { $gte: 2 } } }). Also works on relation count filtering.
$elemMatchArray contains an element matching the condition. E.g. { addresses: { $elemMatch: { city: 'NYC' } } }.
$textFull-text search (where supported by the database).

 

You write
import { User } from './shared/models/index.js';
const users = await querier.findMany(User, {
$select: { id: true, name: true },
$where: {
name: { $istartsWith: 'Some', $ne: 'Something' },
age: { $gte: 18, $lte: 65 }
},
$sort: { name: 'asc' },
$limit: 50
});

UQL transparently handles the differences between database vendors. For example, $istartsWith is translated to ILIKE in PostgreSQL, but to LOWER(field) LIKE 'some%' in MySQL.

Generated SQL (PostgreSQL)
SELECT "id", "name" FROM "User"
WHERE ("name" ILIKE $1 AND "name" IS DISTINCT FROM $2) AND ("age" >= $3 AND "age" <= $4)
ORDER BY "name"
LIMIT 50
Generated SQL (MySQL/MariaDB)
SELECT `id`, `name` FROM `User`
WHERE (LOWER(`name`) LIKE ? AND NOT (`name` <=> ?)) AND (`age` >= ? AND `age` <= ?)
ORDER BY `name`
LIMIT 50
Generated SQL (SQLite)
SELECT `id`, `name` FROM `User`
WHERE (`name` LIKE ? AND `name` IS NOT ?) AND (`age` >= ? AND `age` <= ?)
ORDER BY `name`
LIMIT 50

 

You write
const users = await querier.findMany(User, {
$where: { age: { $between: [18, 65] } },
});
Generated SQL (PostgreSQL)
SELECT * FROM "User" WHERE "age" BETWEEN $1 AND $2

 

All comparison operators listed above also work on nested JSON field paths using dot-notation (e.g., 'settings.isArchived': { $ne: true }). UQL generates dialect-specific SQL automatically across PostgreSQL, MySQL, and SQLite.

See the dedicated JSON / JSONB page for full documentation including filtering, $merge/$unset update operators, and sorting by JSON paths.