Basics
Override: Predicates
Predicate helpers extend how where, logical operators, and membership checks are composed.
Where
where ignores empty statements but still emits the keyword.
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
and, or, and not accept multiple statements and group them correctly.
const query = q
.select(q.c("events.id"))
.from(q.t("events"))
.where(
q.and(
q.gt(q.c("events.score"), q.v(90)),
q.not(q.eq(q.c("events.type"), q.v("test"))),
),
)const query = q
.select(q.c("events.id"))
.from(q.t("events"))
.where(
q.and(
q.gt(q.c("events.score"), q.v(90)),
q.not(q.eq(q.c("events.type"), q.v("test"))),
),
)Membership
in, notIn, exists, andnotExists handle multiple params and subqueries.
const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.where(
q.and(
q.c("users.status").in(q.v("active"), q.v("trial")),
q.notExists(
q.select(q.c("bans.user_id"))
.from(q.t("bans"))
.where(q.eq(q.c("bans.user_id"), q.c("users.id"))),
),
),
)const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.where(
q.and(
q.c("users.status").in(q.v("active"), q.v("trial")),
q.notExists(
q.select(q.c("bans.user_id"))
.from(q.t("bans"))
.where(q.eq(q.c("bans.user_id"), q.c("users.id"))),
),
),
)