Logical Operators
Logical Operators
Section titled “Logical Operators”Logical operators allow you to combine multiple conditions in a single query. UQL uses a MongoDB-inspired syntax that is 100% valid JSON.
| Name | Description |
|---|---|
$and | joins query clauses with a logical AND (default). |
$or | joins query clauses with a logical OR, returns records that match any clause. |
$not | negates the given clause. |
$nor | joins query clauses with a logical OR and then negates the result. |
Implicit vs Explicit $and
Section titled “Implicit vs Explicit $and”The $and operator is implicit when you specify multiple fields in the $where object.
import { pool } from './shared/orm.js';import { User } from './shared/models/index.js';
// Implicit ANDconst users = await pool.transaction(async (querier) => { return querier.findMany(User, { $where: { name: 'roger', status: 'active' }, });});The same query with an explicit $and:
const users = await querier.findMany(User, { $where: { $and: [{ name: 'roger' }, { status: 'active' }] },});
Complex Logical Nesting
Section titled “Complex Logical Nesting”Logical operators can be nested to create complex filters.
const users = await querier.findMany(User, { $where: { $or: [ { name: { $startsWith: 'A' } }, { $and: [ { status: 'pending' }, { createdAt: { $lt: new Date('2025-01-01') } } ] } ] },});That ▲ code will generate clean, parameterized SQL:
SELECT * FROM "User"WHERE "name" LIKE 'A%' OR ("status" = 'pending' AND "createdAt" < '2025-01-01')