Skip to content

CountQueryBuilder

Defined in: src/query/countBuilder.ts:20

Builds and runs a count: how many entities a query matches, without fetching any of them.

It filters exactly as client.select() does — from, where, ownedBy and createdBy are the same methods, from the same base — but has nothing to select and no pages, so fetch resolves to a bigint. Create one with client.count().

To show the total next to a page of rows, use select(...).withCount() instead, which counts in the same request.

const total = await client.count().from(Posts).ownedBy(account.address).fetch()

TSchema extends Schema | undefined = undefined

The schema named with from, if any.

new CountQueryBuilder<TSchema>(client): CountQueryBuilder<TSchema>

Defined in: src/query/builderBase.ts:68

ArkivClient

CountQueryBuilder<TSchema>

QueryBuilderBase<TSchema>.constructor

createdBy(creator): this

Defined in: src/query/builderBase.ts:123

Restricts the query to entities this account created — shorthand for where(eq("$creator", addr(creator))). Calling it again replaces the filter.

The creator never changes; the owner does, so these differ after a transfer.

`0x${string}`

this

QueryBuilderBase.createdBy


fetch(): Promise<bigint>

Defined in: src/query/countBuilder.ts:54

Runs the count.

Counts every entity the filters match at the block, whether or not it fits the schema — what select().from(schema) leaves out of its pages is still counted.

Promise<bigint>

If no filter has been added, or a filter does not fit the schema.

If the node rejects the query.

If the node returns no count — it predates the count projection.


from<S>(schema): CountQueryBuilder<S>

Defined in: src/query/countBuilder.ts:34

Counts through a schema: where is checked against its indexed columns, and a named schema counts only entities tagged with its name — so it needs no other filter.

Returns a new builder, carrying whatever this one already holds; this one is left as it was.

S extends Schema<Columns>

S

CountQueryBuilder<S>

If schema was not built with defineSchema.

client.count().from(Posts) // every post

ownedBy(owner): this

Defined in: src/query/builderBase.ts:112

Restricts the query to entities this account owns — shorthand for where(eq("$owner", addr(owner))). Calling it again replaces the filter.

`0x${string}`

this

builder.ownedBy("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")

QueryBuilderBase.ownedBy


toString(): string

Defined in: src/query/builderBase.ts:135

The query string this builder will send — the same text the node parses: its filters, ownedBy and createdBy, and a named schema’s tag, ANDed.

string

If no filter has been added, or — after from() — a filter does not fit the schema. A named schema’s own tag filter counts as a filter.

QueryBuilderBase.toString


where<E>(…expressions): this

Defined in: src/query/builderBase.ts:98

Adds filters. Everything passed here, and across repeated calls, must hold.

After from(), every attribute a filter names must be an indexed column of the schema, compared against a value of its type — anything else is a compile error.

E extends readonly (Expression | readonly Expression[])[]

…E & FilterCheck<E, TSchema>

The expressions, as separate arguments or one array.

this

builder.where(eq("category", "docs"))
builder.where(gte("level", i32(10)), lt("level", i32(20)))
builder.where(or(eq("status", "open"), exists("reviewedBy")))

QueryBuilderBase.where