Threshold filtering
Filtering records by a threshold such as a timestamp, number, or other comparable column value.
Drizzle ORM · Function
lt creates a strict less-than filter condition in Drizzle ORM. Use it in where clauses to select rows whose column value is below a supplied value.
Import lt from drizzle-orm and pass a column plus a comparison value. It creates a less-than condition that can be supplied to a query's where clause, including relational query filters.
lt(column, value)| Name | Type | Description |
|---|---|---|
column | Column or SQL expression | The table column or SQL expression to compare. |
value | Comparable value | The comparison value, represented as n in the documentation. |
A SQL filter condition representing a strict less-than comparison.
drizzle-orm package.lt matches values strictly below the comparison value.import { lt } from 'drizzle-orm';
import { users } from './schema';
const olderUsers = await db
.select()
.from(users)
.where(lt(users.createdAt, new Date('2024-01-01')));Selects users whose creation timestamp is earlier than the supplied date.
Filtering records by a threshold such as a timestamp, number, or other comparable column value.
Selecting the preceding page when implementing descending cursor-based pagination.
Restricting nested relational records through a relational query where callback.
lt do?lt is Drizzle's less-than filter operator. It receives a column and a value, then produces a condition suitable for a query's where clause.
Follow-up: How would you express the opposite comparison? Use gt when the column value must be greater than the supplied value.
lt used in a query?Import it from drizzle-orm, then call lt(table.column, value) inside .where(...). The result can be combined with other filter operators when building a query.
Follow-up: How can it be used for descending cursor pagination? Use lt to select rows whose cursor is below the current cursor, together with descending ordering.
lt?The operator compares a selected column against the provided value and matches values below it. The documentation also shows it in relational query filters for nested records.
Follow-up: What should the cursor property be for reliable cursor comparison? The documentation recommends that a cursor be unique and sequential.
gtlteeqascdescwhere