Skip to main content

Class: AsyncQueryableRoot<T, E>

Fluent query operators that must appear at the root of a query expression.

Extends

Type Parameters

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

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.

Inherited from

AsyncQueryable.all

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.

Inherited from

AsyncQueryable.any

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 (obj: T, ...args: A) => boolean | (...args: readonly [T, unknown]) => boolean & (obj: T, ...args: A) => boolean | (...args: readonly unknown[]) => 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.

Inherited from

AsyncQueryable.any

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.

Inherited from

AsyncQueryable.array

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.

Inherited from

AsyncQueryable.avg

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.

Inherited from

AsyncQueryable.count

Defined in

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


distinct()

distinct(): AsyncQueryableRoot<T, E>

Removes duplicate elements from the sequence.

Returns

AsyncQueryableRoot<T, E>

The queryable result of the distinct operation.

Inherited from

AsyncQueryable.distinct

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>

Inherited from

AsyncQueryable.execute

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.

Inherited from

AsyncQueryable.first

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.

Inherited from

AsyncQueryable.first

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>

Inherited from

AsyncQueryable.groupBy

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.

Inherited from

AsyncQueryable.groupBy

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.

Inherited from

AsyncQueryable.join

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.

Inherited from

AsyncQueryable.leftJoin

Defined in

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


limit()

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

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

Parameters

ParameterTypeDescription
limitnumberThe number of elements to return.

Returns

AsyncQueryableRoot<T, E>

The queryable result of the limit operation.

Inherited from

AsyncQueryable.limit

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.

Inherited from

AsyncQueryable.max

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.

Inherited from

AsyncQueryable.maybeFirst

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.

Inherited from

AsyncQueryable.maybeFirst

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.

Inherited from

AsyncQueryable.maybeSingle

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.

Inherited from

AsyncQueryable.maybeSingle

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.

Inherited from

AsyncQueryable.min

Defined in

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


offset()

offset(offset: number): AsyncQueryableRoot<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

AsyncQueryableRoot<T, E>

The queryable result of the offset operation.

Inherited from

AsyncQueryable.offset

Defined in

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


options()

options(options: QueryOptions): AsyncQueryableRoot<T, E>

Set query options that affect the behaviour of the query.

Parameters

ParameterTypeDescription
optionsQueryOptionsThe query options.

Returns

AsyncQueryableRoot<T, E>

The queryable with the specified options applied.

Example

const q =
db.from.albums.options({ disabledConditions: ["soft delete"] });

Defined in

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


orderBy()

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

Sorts the elements of a sequence in ascending order.

Type Parameters

Type Parameter
E extends (obj: T, ...args: A) => unknown | (...args: readonly [T, unknown]) => unknown & (obj: T, ...args: A) => unknown | (...args: readonly unknown[]) => 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

AsyncQueryableRoot<T, E>

The queryable result of the orderBy operation.

Inherited from

AsyncQueryable.orderBy

Defined in

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


orderByDesc()

orderByDesc<E, A>(expr: E, ...args: A): AsyncQueryableRoot<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

AsyncQueryableRoot<T, E>

The queryable result of the orderByDesc operation.

Inherited from

AsyncQueryable.orderByDesc

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.

Inherited from

AsyncQueryable.select

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.

Inherited from

AsyncQueryable.single

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.

Inherited from

AsyncQueryable.single

Defined in

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


sql()

sql(strings: TemplateStringsArray, ...values: readonly any[]): AsyncQueryableRoot<T, E>

Inject a raw SQL query using tagged template literals. The returned queryable may be further composed with additional query operators.

Parameters

ParameterTypeDescription
stringsTemplateStringsArrayThe SQL query template string.
...valuesreadonly any[]The values to be inserted into the query.

Returns

AsyncQueryableRoot<T, E>

The queryable result of the injected SQL query.

Example

const id = 1;
const album =
db.from.albums
.sql`select * from "Album" where "AlbumId" = ${id}`
.single();

Defined in

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


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.

Inherited from

AsyncQueryable.sum

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.

Inherited from

AsyncQueryable.toArray

Defined in

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


where()

where<P, A>(predicate: P, ...args: A): AsyncQueryableRoot<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

AsyncQueryableRoot<T, E>

The queryable result of the where operation.

Inherited from

AsyncQueryable.where

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): AsyncQueryableRoot<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

AsyncQueryableRoot<T, E>

The queryable result of the with operation.

Inherited from

AsyncQueryable.with

Defined in

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