#
query
Returns the latest revisions of smart objects. Conditions can be passed in to determine the smart objects. When multiple conditions are passed in, the latest revisions of the smart objects that satisfy all conditions are returned.
#
Type
<T extends new (...args: any) => any>(
query:
| {
ids: string[];
}
| {
publicKey?: string;
mod?: string;
limit?: number;
offset?: number;
order?: "ASC" | "DEC";
}
) => Promise<string[]>;
#
Syntax
await computer.query({ publicKey })
await computer.query({ ids })
await computer.query({ mod })
await computer.query({ publicKey, order })
...
#
Parameters
#
params
An object with the query parameters.
#
Return value
Given the query parameters, returns an array of strings encoding the latest revisions of smart objects that matches the specified conditions.
#
Examples
class A extends Contract { ... }
a = await computer.new(A)
// query by public key
const publicKey = computer.getPublicKey()
const [rev1] = await computer.query({ publicKey })
expect(rev1).to.equal(a._rev)
// query by id
const ids = [a._id]
const [rev2] = await computer.query({ ids })
expect(rev2).to.equal(a._rev)
// query by module specifier
const mod = await computer.export(`export ${A}`)
const b = await computer.new(A, [], mod)
const [rev3] = await computer.query({ mod })
expect(rev3).to.equal(b._rev)
// query by multiple parameters
const [revs5] = await computer.query({
limit: 10,
order: 'ASC',
publicKey: { computer.getPublicKey() }
})
expect(rev5).to.equal(a._rev)