QueryBuilder
Defined in: src/query/queryBuilder.ts:54
QueryBuilder is a helper class to build queries to the Arkiv DBChains. It can be used to fetch entities from the Arkiv DBChains. It follows the Builder pattern allowing chaining of methods.
The Arkiv client
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new QueryBuilder(
client):QueryBuilder
Defined in: src/query/queryBuilder.ts:67
Parameters
Section titled “Parameters”client
Section titled “client”Returns
Section titled “Returns”QueryBuilder
Methods
Section titled “Methods”count()
Section titled “count()”count():
Promise<number>
Defined in: src/query/queryBuilder.ts:316
Counts the entities from the query.
Returns
Section titled “Returns”Promise<number>
The number of entities
Example
Section titled “Example”const builder = new QueryBuilder(client)const result = await builder.where(eq("name", "John")).count()// result = 10createdBy()
Section titled “createdBy()”createdBy(
createdBy):QueryBuilder
Defined in: src/query/queryBuilder.ts:95
Sets the createdBy filter
Parameters
Section titled “Parameters”createdBy
Section titled “createdBy”`0x${string}`
The address of the creator
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.createdBy("0x1234567890123456789012345678901234567890")cursor()
Section titled “cursor()”cursor(
cursor):QueryBuilder
Defined in: src/query/queryBuilder.ts:228
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”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.offset(10)fetch()
Section titled “fetch()”fetch():
Promise<QueryResult>
Defined in: src/query/queryBuilder.ts:283
Fetches the entities from the query. Re It will return a QueryResult instance which can be used to fetch the next and previous pages.
Returns
Section titled “Returns”Promise<QueryResult>
The QueryResult instance QueryResult
Example
Section titled “Example”const builder = new QueryBuilder(client)const result = await builder.where(eq("name", "John")).fetch()// result = { entities: [Entity, Entity, Entity], next: async () => QueryResult, previous: async () => QueryResult }limit()
Section titled “limit()”limit(
limit):QueryBuilder
Defined in: src/query/queryBuilder.ts:214
Sets the limit for the query
Parameters
Section titled “Parameters”number
The number of entities to return
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.limit(10)orderBy()
Section titled “orderBy()”Call Signature
Section titled “Call Signature”orderBy(
attributeName,attributeType,order?):this
Defined in: src/query/queryBuilder.ts:116
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 QueryBuilder instance
Example
Section titled “Example”const builder = client.buildQuery()builder.orderBy("name", "string", "desc")builder.orderBy(asc("name", "string"))builder.orderBy(desc("name", "string"))Call Signature
Section titled “Call Signature”orderBy(
orderByAttribute):this
Defined in: src/query/queryBuilder.ts:129
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 QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.orderBy(asc("name", "string"))builder.orderBy(desc("name", "string"))ownedBy()
Section titled “ownedBy()”ownedBy(
ownedBy):QueryBuilder
Defined in: src/query/queryBuilder.ts:81
Sets the ownedBy filter
Parameters
Section titled “Parameters”ownedBy
Section titled “ownedBy”`0x${string}`
The address of the owner
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.ownedBy("0x1234567890123456789012345678901234567890")validAtBlock()
Section titled “validAtBlock()”validAtBlock(
validAtBlock):QueryBuilder
Defined in: src/query/queryBuilder.ts:243
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”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.validAtBlock(10000)where()
Section titled “where()”where(
predicates):QueryBuilder
Defined in: src/query/queryBuilder.ts:264
Sets the predicates for the query limiting the results. It can be a single predicate or an array of predicates combined with ‘and’. Predicates can be nested using ‘or’ and ‘and’ predicates.
Parameters
Section titled “Parameters”predicates
Section titled “predicates”The predicates to set
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.where(eq("name", "John"))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)])])])builder.where([eq("name", "John"), and([eq("age", 30), or([eq("age", 31), and([eq("age", 32), eq("age", 33)])])])])withAttributes()
Section titled “withAttributes()”withAttributes(
withAttributes):QueryBuilder
Defined in: src/query/queryBuilder.ts:172
Sets the withAttributes flag which will return the attributes for the entities if true
Parameters
Section titled “Parameters”withAttributes
Section titled “withAttributes”boolean = true
The boolean value to set
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.withAttributes(true)withMetadata()
Section titled “withMetadata()”withMetadata(
withMetadata):QueryBuilder
Defined in: src/query/queryBuilder.ts:186
Sets the withMetadata flag which will return the metadata (like owner, expiredAt, etc.) for the entities if true
Parameters
Section titled “Parameters”withMetadata
Section titled “withMetadata”boolean = true
The boolean value to set
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.withMetadata(true)withPayload()
Section titled “withPayload()”withPayload(
withPayload):QueryBuilder
Defined in: src/query/queryBuilder.ts:200
Sets the withPayload flag which will return the payload for the entities if true
Parameters
Section titled “Parameters”withPayload
Section titled “withPayload”boolean = true
The boolean value to set
Returns
Section titled “Returns”QueryBuilder
The QueryBuilder instance
Example
Section titled “Example”const builder = new QueryBuilder(client)builder.withPayload(true)