Basics
Operators
Operator helpers are thin wrappers around op. Pass two statements for binary operators, one statement for unary operators, or none to emit the operator token for raw fragments.
Comparison
Equality and ordering helpers such as eq, ne,lt, lte, gt, and gte.
const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.where(q.eq(q.c("users.status"), q.v("active")))const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.where(q.eq(q.c("users.status"), q.v("active")))Logical
Logical helpers such as is, isNot, andexclamation.
const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.where(q.is(q.c("users.deleted_at"), q.raw`NULL`))const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.where(q.is(q.c("users.deleted_at"), q.raw`NULL`))Pattern Matching
LIKE/ILIKE and regex operators: like, ilike,notLike, matchRegex, and friends.
const query = q
.select(q.c("users.email"))
.from(q.t("users"))
.where(q.ilike(q.c("users.email"), q.v("%@example.com")))const query = q
.select(q.c("users.email"))
.from(q.t("users"))
.where(q.ilike(q.c("users.email"), q.v("%@example.com")))Bitwise
Bitwise helpers such as bitwiseAnd, bitwiseOr, and shift operators.
const query = q
.select(q.c("flags.value"))
.from(q.t("flags"))
.where(q.bitwiseAnd(q.c("flags.value"), q.v(4)))const query = q
.select(q.c("flags.value"))
.from(q.t("flags"))
.where(q.bitwiseAnd(q.c("flags.value"), q.v(4)))Arithmetic
Arithmetic helpers such as plus, minus,multiply, divide, and modulo.
const query = q
.select(q.plus(q.c("orders.total"), q.v(10)))
.from(q.t("orders"))const query = q
.select(q.plus(q.c("orders.total"), q.v(10)))
.from(q.t("orders"))PostgreSQL Specific
PostgreSQL operator helpers such as atSign,hash, and caretAt.
const query = q
.select(q.c("tags.label"))
.from(q.t("tags"))
.where(q.atSign(q.c("tags.label"), q.v("admin")))const query = q
.select(q.c("tags.label"))
.from(q.t("tags"))
.where(q.atSign(q.c("tags.label"), q.v("admin")))Geometric
Geometric operators such as distance, closestPoint, and totalLength.
const query = q
.select(q.c("places.id"))
.from(q.t("places"))
.orderBy(q.distance(q.c("places.location"), q.v("(0,0)")))const query = q
.select(q.c("places.id"))
.from(q.t("places"))
.orderBy(q.distance(q.c("places.location"), q.v("(0,0)")))Between
Between helpers such as between, notBetween, and symmetric variants.
const query = q
.select(q.c("events.created_at"))
.from(q.t("events"))
.where(q.between(q.v("2024-01-01"), q.v("2024-01-31")))const query = q
.select(q.c("events.created_at"))
.from(q.t("events"))
.where(q.between(q.v("2024-01-01"), q.v("2024-01-31")))Operator Index
Complete list of operator helpers grouped by category.
Showing 15 of 60
| # | Operator Helper | SQL | Group |
|---|---|---|---|
| 1 | eq | = | Comparison |
| 2 | ne | <> | Comparison |
| 3 | notEq | != | Comparison |
| 4 | lt | < | Comparison |
| 5 | gt | > | Comparison |
| 6 | lte | <= | Comparison |
| 7 | gte | >= | Comparison |
| 8 | exclamation | ! | Logical |
| 9 | is | IS | Logical |
| 10 | isNot | IS NOT | Logical |
| 11 | matchRegex | ~ | Pattern Matching |
| 12 | matchRegexInsensitive | ~* | Pattern Matching |
| 13 | notMatchRegex | !~ | Pattern Matching |
| 14 | notMatchRegexInsensitive | !~* | Pattern Matching |
| 15 | like | LIKE | Pattern Matching |
Page 1 of 4