Skip to content

QueryBuilder

QueryBuilder = object

Defined in: packages/db/src/types.ts:428

Builder for read queries on a single table.

Returned by db.query(table). Provides findMany, findFirst, and paginate methods that each return an Operation with permission-aware execution.

const builder = db.query(posts);
// Fetch all visible posts
const all = await builder.findMany().run({});
// Fetch a single post
const post = await builder.findFirst({ where: eq(posts.id, id) }).run({});
// Paginate
const page = await builder.paginate(params, { orderBy: desc(posts.createdAt) }).run({});

findFirst: (options?) => Operation<unknown | undefined>

Defined in: packages/db/src/types.ts:432

Returns an Operation that fetches the first matching row, or undefined if none match.

FindFirstOptions

Operation<unknown | undefined>


findMany: (options?) => Operation<unknown[]>

Defined in: packages/db/src/types.ts:430

Returns an Operation that fetches multiple rows matching the given options.

FindManyOptions

Operation<unknown[]>


paginate: (params, options?) => Operation<CursorPage<unknown>> | Operation<OffsetPage<unknown>>

Defined in: packages/db/src/types.ts:439

Returns a paginated Operation using either cursor-based or offset-based strategy.

The return type depends on the params.type discriminant: CursorPage for "cursor", OffsetPage for "offset".

CursorParams | OffsetParams

PaginateOptions

Operation<CursorPage<unknown>> | Operation<OffsetPage<unknown>>