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.
Example
Section titled “Example”const total = await client.count().from(Posts).ownedBy(account.address).fetch()Extends
Section titled “Extends”QueryBuilderBase<TSchema>
Type Parameters
Section titled “Type Parameters”TSchema
Section titled “TSchema”TSchema extends Schema | undefined = undefined
The schema named with from, if any.
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new CountQueryBuilder<
TSchema>(client):CountQueryBuilder<TSchema>
Defined in: src/query/builderBase.ts:68
Parameters
Section titled “Parameters”client
Section titled “client”Returns
Section titled “Returns”CountQueryBuilder<TSchema>
Inherited from
Section titled “Inherited from”QueryBuilderBase<TSchema>.constructor
Methods
Section titled “Methods”createdBy()
Section titled “createdBy()”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.
Parameters
Section titled “Parameters”creator
Section titled “creator”`0x${string}`
Returns
Section titled “Returns”this
Inherited from
Section titled “Inherited from”fetch()
Section titled “fetch()”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.
Returns
Section titled “Returns”Promise<bigint>
Throws
Section titled “Throws”If no filter has been added, or a filter does not fit the schema.
Throws
Section titled “Throws”If the node rejects the query.
Throws
Section titled “Throws”If the node returns no count — it predates the count projection.
from()
Section titled “from()”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.
Type Parameters
Section titled “Type Parameters”Parameters
Section titled “Parameters”schema
Section titled “schema”S
Returns
Section titled “Returns”CountQueryBuilder<S>
Throws
Section titled “Throws”If schema was not built with defineSchema.
Example
Section titled “Example”client.count().from(Posts) // every postownedBy()
Section titled “ownedBy()”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.
Parameters
Section titled “Parameters”`0x${string}`
Returns
Section titled “Returns”this
Example
Section titled “Example”builder.ownedBy("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045")Inherited from
Section titled “Inherited from”toString()
Section titled “toString()”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.
Returns
Section titled “Returns”string
Throws
Section titled “Throws”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.
Inherited from
Section titled “Inherited from”where()
Section titled “where()”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.
Type Parameters
Section titled “Type Parameters”E extends readonly (Expression | readonly Expression[])[]
Parameters
Section titled “Parameters”expressions
Section titled “expressions”…E & FilterCheck<E, TSchema>
The expressions, as separate arguments or one array.
Returns
Section titled “Returns”this
Example
Section titled “Example”builder.where(eq("category", "docs"))builder.where(gte("level", i32(10)), lt("level", i32(20)))builder.where(or(eq("status", "open"), exists("reviewedBy")))