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.
$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.
$textFull-text search (where supported by the database).

 

import { pool } from './shared/orm.js';
import { User } from './shared/models/index.js';
const users = await pool.transaction(async (querier) => {
return querier.findMany(User, {
$select: { id: true, name: true },
$where: {
name: { $istartsWith: 'Some', $ne: 'Something' },
age: { $gte: 18, $lte: 65 }
},
$sort: { name: 1 },
$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.

SQL for PostgreSQL:

SELECT "id", "name" FROM "User"
WHERE "name" ILIKE 'Some%' AND "name" <> 'Something' AND "age" >= 18 AND "age" <= 65
ORDER BY "name" ASC
LIMIT 50

SQL for MySQL/SQLite:

SELECT `id`, `name` FROM `User`
WHERE LOWER(`name`) LIKE 'some%' AND `name` <> 'Something' AND `age` >= 18 AND `age` <= 65
ORDER BY `name` ASC
LIMIT 50