Basics
Override: Ordering & Fetch
Override ordering helpers add multi-column ordering, nulls handling, and fetch/ties clauses.
Order By
Use orderBy with asc or desc to set per-column direction.
const query = q
.select(q.c("events.id"))
.from(q.t("events"))
.orderBy(q.c("events.created_at"))
.desc(q.c("events.priority"))const query = q
.select(q.c("events.id"))
.from(q.t("events"))
.orderBy(q.c("events.created_at"))
.desc(q.c("events.priority"))Nulls Position
nullsFirst and nullsLast apply to the last ordering clause.
const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.orderBy(q.c("users.last_login"))
.nullsLast()const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.orderBy(q.c("users.last_login"))
.nullsLast()Limit / Fetch
fetch emits FETCH FIRST/NEXT ... ROWS with optional ties.
const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.fetch(q.v(5), "next", true)const query = q
.select(q.c("users.id"))
.from(q.t("users"))
.fetch(q.v(5), "next", true)