Reading data
Fetch one record or many with Strata ORM, then filter, select, sort, paginate and iterate the results.
Every query chains methods on a model, and the last call in the chain says what you want back and runs the query — usually .all() or .first().
Example schema
The examples on this page use the User and Post models from the data contract.
Fetch many records or one
Filter records
Filters are plain objects. Several keys mean and; use or for alternatives.
const recent = await db.post
.where({
published: true,
createdAt: { gte: new Date("2026-01-01") },
or: [{ title: { contains: "launch" } }, { title: { contains: "release" } }],
})
.all();Filter operators
Operator | Meaning | Example |
|---|---|---|
| Exact match (the default) |
|
| Any of a list |
|
| Substring, case-sensitive |
|
| Range |
|
| Negation |
|
Select fields
const emails = await db.user.select({ id: true, email: true }).all();
// ^? { id: string; email: string }[]Sort and paginate
const page2 = await db.post.orderBy({ createdAt: "desc" }).skip(20).take(20).all();Cursor pagination
Offset pagination slows down as the offset grows. For long lists, page by a cursor instead:
const next = await db.post.orderBy({ id: "asc" }).after({ id: lastId }).take(50).all();Count records
const drafts = await db.post.where({ published: false }).count();Iterate a large result
.iterate() streams rows in batches so a million-row export never sits in memory at once.
for await (const post of db.post.iterate({ batchSize: 500 })) {
await index(post);
}An iterated result can only be read once. Calling .iterate() again on the same query object throws STR_2041.
Common mistakes
Fetching everything to use one record
.all()[0] loads every matching row first. Use .first(), which adds LIMIT 1.
Forgetting that .all() has no limit
A list endpoint without .take() returns every row. Always cap user-facing lists.