Skip to main content

Class: AsyncQueryable<T, E>

Fluent query operators used when constructing queries.

A query can be created by accessing entity sets exposed by the Verse.from property.

Example

const customer =
await db.from.customers
.where(c => c.name === "ACME Corp.")
.single();

Extended by

Type Parameters

Type ParameterDescription
TThe type of the entity being queried.
E extends Entities-

Implements

Methods

all()

all<P, A>(predicate: P, ...args: A): Promise<boolean>

Determines whether all elements of a sequence satisfy a condition.

Type Parameters

Type Parameter
P extends (...args: readonly unknown[]) => boolean | (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean
A extends unknown[]

Parameters

ParameterTypeDescription
predicatePA function to test each element for a condition.
...argsAAdditional arguments to be passed to the predicate.

Returns

Promise<boolean>

A promise that resolves with true if all elements in the sequence satisfy the condition, otherwise false.

Defined in

packages/verse-core/src/query/queryable.ts:721


any()

any()

any(): Promise<boolean>

Determines whether a sequence contains any elements.

Returns

Promise<boolean>

A promise that resolves with true if the sequence contains any elements, otherwise false.

Defined in

packages/verse-core/src/query/queryable.ts:694

any(predicate, args)

any<P, A>(predicate: P, ...args: A): Promise<boolean>

Determines whether any element of a sequence satisfies a condition.

Type Parameters
Type Parameter
P extends (...args: readonly unknown[]) => boolean | (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean
A extends unknown[]
Parameters
ParameterTypeDescription
predicatePA function to test each element for a condition.
...argsAAdditional arguments to be passed to the predicate.
Returns

Promise<boolean>

A promise that resolves with true if any elements in the sequence satisfy the condition, otherwise false.

Defined in

packages/verse-core/src/query/queryable.ts:703


array()

array(): AsyncQueryable<T[], E>

Aggregates the elements of the sequence into an array.

Returns

AsyncQueryable<T[], E>

The queryable result of the array operation.

Defined in

packages/verse-core/src/query/queryable.ts:891


avg()

avg(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): Promise<number>

Returns the average value of the specified numerical expression for the sequence.

Parameters

ParameterTypeDescription
expr?T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => numberThe numerical expression to be evaluated.

Returns

Promise<number>

A promise that resolves with the average value of the specified numerical expression for the sequence.

Defined in

packages/verse-core/src/query/queryable.ts:881


count()

count(): Promise<number>

Returns the number of elements in the sequence.

Returns

Promise<number>

A promise that resolves with the number of elements in the sequence.

Defined in

packages/verse-core/src/query/queryable.ts:837


distinct()

distinct(): AsyncQueryable<T, E>

Removes duplicate elements from the sequence.

Returns

AsyncQueryable<T, E>

The queryable result of the distinct operation.

Defined in

packages/verse-core/src/query/queryable.ts:537


execute()

protected execute(cache?: QueryCache): Promise<undefined> | AsyncSequenceImpl<any>

Parameters

ParameterType
cache?QueryCache

Returns

Promise<undefined> | AsyncSequenceImpl<any>

Defined in

packages/verse-core/src/query/queryable.ts:969


first()

first()

first(): Promise<T>

Returns the first element of a sequence.

Returns

Promise<T>

A promise that resolves with the first element in the sequence.

Throws

Error, if no such element is found.

Defined in

packages/verse-core/src/query/queryable.ts:733

first(predicate, args)

first<P, A>(predicate?: P, ...args?: A): Promise<T>

Returns the first element of a sequence that satisfies a specified condition.

Type Parameters
Type Parameter
P extends (...args: readonly unknown[]) => boolean | (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean
A extends unknown[]
Parameters
ParameterTypeDescription
predicate?PA function to test each element for a condition.
...args?AAdditional arguments to be passed to the predicate.
Returns

Promise<T>

A promise that resolves with the first element in the sequence that satisfies the condition.

Throws

Error, if no such element is found.

Defined in

packages/verse-core/src/query/queryable.ts:743


groupBy()

groupBy(key)

groupBy<K>(key: K): AsyncQueryable<{items: T[];key: ReturnType<K>; }, E>

Groups the elements of a sequence according to a specified key selector function.

Type Parameters
Type Parameter
K extends (obj: T) => unknown | (...args: readonly unknown[]) => unknown
Parameters
ParameterTypeDescription
keyKA function to extract the key for each element.
Returns

AsyncQueryable<{items: T[];key: ReturnType<K>; }, E>

The result of the groupBy operation.

items

items: T[]

key

key: ReturnType<K>

Defined in

packages/verse-core/src/query/queryable.ts:636

groupBy(key, result)

groupBy<K, R>(key: K, result: (param: Grouping<ReturnType<K>, T>) => R): AsyncQueryable<R, E>

Groups the elements of a sequence according to a specified key selector function and creates a result value from each group.

Type Parameters
Type Parameter
K extends (...args: readonly unknown[]) => unknown | (obj: T) => unknown
R
Parameters
ParameterTypeDescription
keyKA function to extract the key for each element.
result(param: Grouping<ReturnType<K>, T>) => RA function to create a result value from each group.
Returns

AsyncQueryable<R, E>

The queryable result of the groupBy operation.

Defined in

packages/verse-core/src/query/queryable.ts:648


join()

join<S, C>(entityOrQuery: Newable<S> | AsyncQueryable<S, E>, condition: C): AsyncQueryable<JoinResult<Parameters<C>>, E>

Joins the sequence with another sequence based on a condition.

Type Parameters

Type Parameter
S
C extends (left: T, right: S) => boolean | (...args: readonly [unknown, S]) => boolean

Parameters

ParameterTypeDescription
entityOrQueryNewable<S> | AsyncQueryable<S, E>The entity or query to join with.
conditionCThe join condition.

Returns

AsyncQueryable<JoinResult<Parameters<C>>, E>

The queryable result of the join operation.

Defined in

packages/verse-core/src/query/queryable.ts:550


leftJoin()

leftJoin<S, C>(entityOrQuery: Newable<S> | AsyncQueryable<S, E>, condition: C): AsyncQueryable<JoinResult<Parameters<C>>, E>

Left joins the sequence with another sequence based on a condition.

Type Parameters

Type Parameter
S
C extends (left: T, right: S) => boolean | (...args: readonly [unknown, S]) => boolean

Parameters

ParameterTypeDescription
entityOrQueryNewable<S> | AsyncQueryable<S, E>The entity or query to join with.
conditionCThe join condition.

Returns

AsyncQueryable<JoinResult<Parameters<C>>, E>

The queryable result of the join operation.

Defined in

packages/verse-core/src/query/queryable.ts:571


limit()

limit(limit: number): AsyncQueryable<T, E>

Returns a specified number of contiguous elements from the start of a sequence.

Parameters

ParameterTypeDescription
limitnumberThe number of elements to return.

Returns

AsyncQueryable<T, E>

The queryable result of the limit operation.

Defined in

packages/verse-core/src/query/queryable.ts:671


max()

max(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): Promise<number>

Returns the maximum value of the specified numerical expression for the sequence.

Parameters

ParameterTypeDescription
expr?T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => numberThe numerical expression to be evaluated.

Returns

Promise<number>

A promise that resolves with the maximum value of the specified numerical expression for the sequence.

Defined in

packages/verse-core/src/query/queryable.ts:859


maybeFirst()

maybeFirst()

maybeFirst(): Promise<undefined | T>

Returns the first element of a sequence, or undefined if no such element is found.

Returns

Promise<undefined | T>

A promise that resolves with the first element in the sequence, or undefined if no such element is found.

Defined in

packages/verse-core/src/query/queryable.ts:757

maybeFirst(predicate, args)

maybeFirst<P, A>(predicate?: P, ...args?: A): Promise<undefined | T>

Returns the first element of a sequence that satisfies a specified condition, or undefined if no such element is found.

Type Parameters
Type Parameter
P extends (...args: readonly unknown[]) => boolean | (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean
A extends unknown[]
Parameters
ParameterTypeDescription
predicate?PA function to test each element for a condition.
...args?AAdditional arguments to be passed to the predicate.
Returns

Promise<undefined | T>

A promise that resolves with the first element in the sequence that satisfies the condition, or undefined if no such element is found.

Defined in

packages/verse-core/src/query/queryable.ts:768


maybeSingle()

maybeSingle()

maybeSingle(): Promise<undefined | T>

Returns the only element of a sequence, or undefined if no such element is found.

Returns

Promise<undefined | T>

A promise that resolves with the only element in the sequence, or undefined if no such element is found.

Throws

Error, if multiple elements satisfy the condition.

Defined in

packages/verse-core/src/query/queryable.ts:810

maybeSingle(predicate, args)

maybeSingle<P, A>(predicate?: P, ...args?: A): Promise<undefined | T>

Returns the only element of a sequence that satisfies a specified condition, or undefined if no such element is found.

Type Parameters
Type Parameter
P extends (...args: readonly unknown[]) => boolean | (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean
A extends unknown[]
Parameters
ParameterTypeDescription
predicate?PA function to test each element for a condition.
...args?AAdditional arguments to be passed to the predicate.
Returns

Promise<undefined | T>

A promise that resolves with the only element in the sequence that satisfies the condition, or undefined if no such element is found.

Throws

Error, if multiple elements satisfy the condition.

Defined in

packages/verse-core/src/query/queryable.ts:821


min()

min(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): Promise<number>

Returns the minimum value of the specified numerical expression for the sequence.

Parameters

ParameterTypeDescription
expr?T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => numberThe numerical expression to be evaluated.

Returns

Promise<number>

A promise that resolves with the minimum value of the specified numerical expression for the sequence.

Defined in

packages/verse-core/src/query/queryable.ts:848


offset()

offset(offset: number): AsyncQueryable<T, E>

Skips a specified number of elements in a sequence and then returns the remaining elements.

Parameters

ParameterTypeDescription
offsetnumberThe number of elements to skip.

Returns

AsyncQueryable<T, E>

The queryable result of the offset operation.

Defined in

packages/verse-core/src/query/queryable.ts:683


orderBy()

orderBy<E, A>(expr: E, ...args: A): AsyncQueryable<T, E>

Sorts the elements of a sequence in ascending order.

Type Parameters

Type Parameter
E extends (...args: readonly unknown[]) => unknown | (obj: T, ...args: A) => unknown | (...args: readonly [T, unknown]) => unknown & (obj: T, ...args: A) => unknown
A extends unknown[]

Parameters

ParameterTypeDescription
exprEA function to extract a sort key from an element.
...argsAAdditional arguments to be passed to the expression.

Returns

AsyncQueryable<T, E>

The queryable result of the orderBy operation.

Defined in

packages/verse-core/src/query/queryable.ts:605


orderByDesc()

orderByDesc<E, A>(expr: E, ...args: A): AsyncQueryable<T, E>

Sorts the elements of a sequence in descending order.

Type Parameters

Type Parameter
E extends (...args: readonly unknown[]) => unknown | (obj: T, ...args: A) => unknown | (...args: readonly [T, unknown]) => unknown & (obj: T, ...args: A) => unknown
A extends unknown[]

Parameters

ParameterTypeDescription
exprEA function to extract a sort key from an element.
...argsAAdditional arguments to be passed to the expression.

Returns

AsyncQueryable<T, E>

The queryable result of the orderByDesc operation.

Defined in

packages/verse-core/src/query/queryable.ts:621


select()

select<P, A>(projector: P, ...args: A): AsyncQueryable<ReturnType<P>, E>

Projects each element of a sequence into a new form.

Type Parameters

Type Parameter
P extends (obj: T, ...args: readonly [A, From<E>]) => unknown | (...args: readonly [unknown, A, From<E>]) => unknown
A extends unknown[]

Parameters

ParameterTypeDescription
projectorPA function that transforms the input element.
...argsAAdditional arguments to be passed to the projector.

Returns

AsyncQueryable<ReturnType<P>, E>

The queryable result of the select operation.

Defined in

packages/verse-core/src/query/queryable.ts:511


single()

single()

single(): Promise<T>

Returns the only element of a sequence.

Returns

Promise<T>

A promise that resolves with the only element in the sequence.

Throws

Error, if no such element is found, or there are multiple elements in the sequence.

Defined in

packages/verse-core/src/query/queryable.ts:785

single(predicate, args)

single<P, A>(predicate?: P, ...args?: A): Promise<T>

Returns the only element of a sequence that satisfies a specified condition.

Type Parameters
Type Parameter
P extends (...args: readonly unknown[]) => boolean | (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean
A extends unknown[]
Parameters
ParameterTypeDescription
predicate?PA function to test each element for a condition.
...args?AAdditional arguments to be passed to the predicate.
Returns

Promise<T>

A promise that resolves with the only element in the sequence that satisfies the condition.

Throws

Error, if no such element is found, or multiple elements satisfy the condition.

Defined in

packages/verse-core/src/query/queryable.ts:795


sum()

sum(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): Promise<number>

Returns the sum of the specified numerical expression for the sequence.

Parameters

ParameterTypeDescription
expr?T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => numberThe numerical expression to be evaluated.

Returns

Promise<number>

A promise that resolves with the sum of the specified numerical expression for the sequence.

Defined in

packages/verse-core/src/query/queryable.ts:870


toArray()

toArray(): Promise<T[]>

Buffers the sequence into an array of type T.

Returns

Promise<T[]>

A promise that resolves with an array of type T.

Implementation of

AsyncSequence.toArray

Defined in

packages/verse-core/src/query/queryable.ts:902


where()

where<P, A>(predicate: P, ...args: A): AsyncQueryable<T, E>

Filters a sequence of values based on a predicate.

Type Parameters

Type Parameter
P extends (obj: T, ...args: readonly [A, From<E>]) => boolean | (...args: readonly [unknown, A, From<E>]) => boolean
A extends unknown[]

Parameters

ParameterTypeDescription
predicatePA function to test each element for a condition.
...argsAAdditional arguments to be passed to the predicate.

Returns

AsyncQueryable<T, E>

The queryable result of the where operation.

Defined in

packages/verse-core/src/query/queryable.ts:592


with()

with<S>(navigation: T extends JoinResult<K> ? (...args: readonly [K]) => S : (obj: T) => S): AsyncQueryable<T, E>

Used to specify eager loading of related entities in queries.

Type Parameters

Type Parameter
S

Parameters

ParameterTypeDescription
navigationT extends JoinResult<K> ? (...args: readonly [K]) => S : (obj: T) => SThe navigation property to be loaded.

Returns

AsyncQueryable<T, E>

The queryable result of the with operation.

Defined in

packages/verse-core/src/query/queryable.ts:526