SelectQueryBuilder
Defined in: src/query/queryBuilder.ts:430
SelectQueryBuilder is the recommended query builder. It requires the selection to be declared up front, so results always contain exactly the data you asked for — and the type of each returned entity is narrowed to exactly the selected fields.
The selection is fixed at construction time and is flat — each field maps to an entity field.
Create one via client.select(...) rather than constructing it directly, so the result type is
inferred from the selection.
Example
Section titled “Example”// everythingawait client.select().where(eq("name", "John")).fetch()await client.select("*").where(eq("name", "John")).fetch()// specific fieldsawait client.select({ owner: true, attributes: true }).fetch()// a single field — result is typed (flat) { owner: Hex }await client.select({ owner: true }).fetch()Extends
Section titled “Extends”BaseQueryBuilder<TEntity>
Type Parameters
Section titled “Type Parameters”TEntity
Section titled “TEntity”TEntity
The projected entity shape, inferred from the selection by client.select().
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SelectQueryBuilder<
TEntity>(client,selection?):SelectQueryBuilder<TEntity>
Defined in: src/query/queryBuilder.ts:433
Parameters
Section titled “Parameters”client
Section titled “client”selection?
Section titled “selection?”"*" | Required<Pick<SelectionFields, "key">> & Partial<Omit<SelectionFields, "key">> | Required<Pick<SelectionFields, "contentType">> & Partial<Omit<SelectionFields, "contentType">> | Required<Pick<SelectionFields, "owner">> & Partial<Omit<SelectionFields, "owner">> | Required<Pick<SelectionFields, "creator">> & Partial<Omit<SelectionFields, "creator">> | Required<Pick<SelectionFields, "expiresAtBlock">> & Partial<Omit<SelectionFields, "expiresAtBlock">> | Required<Pick<SelectionFields, "createdAtBlock">> & Partial<Omit<SelectionFields, "createdAtBlock">> | Required<Pick<SelectionFields, "lastModifiedAtBlock">> & Partial<Omit<SelectionFields, "lastModifiedAtBlock">> | Required<Pick<SelectionFields, "transactionIndexInBlock">> & Partial<Omit<SelectionFields, "transactionIndexInBlock">> | Required<Pick<SelectionFields, "operationIndexInTransaction">> & Partial<Omit<SelectionFields, "operationIndexInTransaction">> | Required<Pick<SelectionFields, "attributes">> & Partial<Omit<SelectionFields, "attributes">> | Required<Pick<SelectionFields, "payload">> & Partial<Omit<SelectionFields, "payload">>
Returns
Section titled “Returns”SelectQueryBuilder<TEntity>
Overrides
Section titled “Overrides”Methods
Section titled “Methods”count()
Section titled “count()”count():
Promise<number>
Defined in: src/query/queryBuilder.ts:317
Counts the entities from the query.
Returns
Section titled “Returns”Promise<number>
The number of entities
Example
Section titled “Example”const builder = client.select()const result = await builder.where(eq("name", "John")).count()// result = 10Inherited from
Section titled “Inherited from”createdBy()
Section titled “createdBy()”createdBy(
createdBy):this
Defined in: src/query/queryBuilder.ts:123
Sets the createdBy filter
Parameters
Section titled “Parameters”createdBy
Section titled “createdBy”`0x${string}`
The address of the creator
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.createdBy("0x1234567890123456789012345678901234567890")Inherited from
Section titled “Inherited from”cursor()
Section titled “cursor()”cursor(
cursor):this
Defined in: src/query/queryBuilder.ts:222
Sets the cursor for the query - it is advances setting which rather shouldn’t be used manually but it is provided from query result if limit is used (pagination).
Parameters
Section titled “Parameters”cursor
Section titled “cursor”string
The cursor to set which tells to RPC Query server where to start or continue the query.
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.cursor("0xABC123")Inherited from
Section titled “Inherited from”fetch()
Section titled “fetch()”fetch():
Promise<QueryResult<TEntity>>
Defined in: src/query/queryBuilder.ts:288
Fetches the entities from the query. It will return a QueryResult instance which can be used to fetch the next and previous pages.
Returns
Section titled “Returns”Promise<QueryResult<TEntity>>
The QueryResult instance QueryResult
Example
Section titled “Example”const builder = client.select()const result = await builder.where(eq("name", "John")).fetch()// result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }Inherited from
Section titled “Inherited from”limit()
Section titled “limit()”limit(
limit):this
Defined in: src/query/queryBuilder.ts:208
Sets the limit for the query
Parameters
Section titled “Parameters”number
The number of entities to return
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.limit(10)Inherited from
Section titled “Inherited from”orderBy()
Section titled “orderBy()”Call Signature
Section titled “Call Signature”orderBy(
attributeName,attributeType,order?):this
Defined in: src/query/queryBuilder.ts:148
Sets the orderBy for the query. It can be called multiple times to order by multiple attributes. The order of the attributes is important. The first attribute is the primary order by attribute. You can use the helper functions asc() and desc() as input for this method.
Parameters
Section titled “Parameters”attributeName
Section titled “attributeName”string
The name of the attribute to order by
attributeType
Section titled “attributeType”The type of the attribute to order by (string or number)
"string" | "number"
order?
Section titled “order?”The order to set the order by (asc or desc)
"asc" | "desc"
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.orderBy("name", "string", "desc")builder.orderBy(asc("name", "string"))builder.orderBy(desc("name", "string"))Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”orderBy(
orderByAttribute):this
Defined in: src/query/queryBuilder.ts:165
Sets the orderBy for the query. This method takes the OrderByAttribute object as an argument and is mainly used to use the helper functions asc() and desc() to create the OrderByAttribute instances.
Parameters
Section titled “Parameters”orderByAttribute
Section titled “orderByAttribute”The OrderByAttribute instance to set
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.orderBy(asc("name", "string"))builder.orderBy(desc("name", "string"))Inherited from
Section titled “Inherited from”ownedBy()
Section titled “ownedBy()”ownedBy(
ownedBy):this
Defined in: src/query/queryBuilder.ts:109
Sets the ownedBy filter
Parameters
Section titled “Parameters”ownedBy
Section titled “ownedBy”`0x${string}`
The address of the owner
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.ownedBy("0x1234567890123456789012345678901234567890")Inherited from
Section titled “Inherited from”validAtBlock()
Section titled “validAtBlock()”validAtBlock(
validAtBlock):this
Defined in: src/query/queryBuilder.ts:237
Sets the validAtBlock for the query which tells at which block height the state we are intested. If not set, the latest block is used.
Parameters
Section titled “Parameters”validAtBlock
Section titled “validAtBlock”bigint
The block number to set
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.validAtBlock(10000)Inherited from
Section titled “Inherited from”where()
Section titled “where()”Call Signature
Section titled “Call Signature”where(
predicates):this
Defined in: src/query/queryBuilder.ts:259
Sets the predicates for the query limiting the results. It can be a single predicate, multiple predicates passed as separate arguments, or an array of predicates - all combined with ‘and’. Predicates can be nested using ‘or’ and ‘and’ predicates.
Parameters
Section titled “Parameters”predicates
Section titled “predicates”The predicates to set, either as a single array or as separate arguments
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.where(eq("name", "John"))builder.where(eq("name", "John"), eq("age", 30))builder.where([eq("name", "John"), eq("age", 30)])builder.where(eq("name", "John"), or(eq("age", 30), eq("age", 31)))builder.where(eq("name", "John"), and(eq("age", 30), eq("age", 31)))builder.where(eq("name", "John"), or(eq("age", 30), and(eq("age", 31), eq("age", 32))))builder.where(eq("name", "John"), and(eq("age", 30), or(eq("age", 31), eq("age", 32))))Inherited from
Section titled “Inherited from”Call Signature
Section titled “Call Signature”where(…
predicates):this
Defined in: src/query/queryBuilder.ts:260
Sets the predicates for the query limiting the results. It can be a single predicate, multiple predicates passed as separate arguments, or an array of predicates - all combined with ‘and’. Predicates can be nested using ‘or’ and ‘and’ predicates.
Parameters
Section titled “Parameters”predicates
Section titled “predicates”…Predicate[]
The predicates to set, either as a single array or as separate arguments
Returns
Section titled “Returns”this
The query builder instance
Example
Section titled “Example”const builder = client.select()builder.where(eq("name", "John"))builder.where(eq("name", "John"), eq("age", 30))builder.where([eq("name", "John"), eq("age", 30)])builder.where(eq("name", "John"), or(eq("age", 30), eq("age", 31)))builder.where(eq("name", "John"), and(eq("age", 30), eq("age", 31)))builder.where(eq("name", "John"), or(eq("age", 30), and(eq("age", 31), eq("age", 32))))builder.where(eq("name", "John"), and(eq("age", 30), or(eq("age", 31), eq("age", 32))))