Skip to main content

Class: Queryable<T>

Fluent query operators used when constructing compiled queries.

A compiled query can be created using the Verse.compile or Verse.compileUow methods.

Example

const query = db.compile((from, $name: string) =>
from.customers.where(c => c.name === $name).single());

const customer = await query("ACME Corp.");

Extended by

Type Parameters

Type ParameterDescription
TThe type of the entity being queried.

Constructors

new Queryable()

new Queryable<T>(): Queryable<T>

Returns

Queryable<T>

Methods

all()

all<P>(predicate: P): boolean

Determines whether all elements of a sequence satisfy a condition.

Type Parameters

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

Parameters

ParameterTypeDescription
predicatePA function to test each element for a condition.

Returns

boolean

true if all elements in the sequence satisfy the condition, otherwise false.

Defined in

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


any()

any<P>(predicate?: P): boolean

Determines whether any element of a sequence satisfies a condition.

Type Parameters

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

Parameters

ParameterTypeDescription
predicate?PA function to test each element for a condition.

Returns

boolean

true if any elements in the sequence satisfy the condition, otherwise false.

Defined in

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


array()

array(): Queryable<T[]>

Aggregates the elements of the sequence into an array.

Returns

Queryable<T[]>

An array of the elements in the sequence.

Defined in

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


avg()

avg(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): 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

number

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

Defined in

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


count()

count(): number

Returns the number of elements in the sequence.

Returns

number

The number of elements in the sequence.

Defined in

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


distinct()

distinct(): Queryable<T>

Removes duplicate elements from the sequence.

Returns

Queryable<T>

The queryable result of the distinct operation.

Defined in

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


first()

first<P>(predicate?: P): T

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

Type Parameters

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

Parameters

ParameterTypeDescription
predicate?PA function to test each element for a condition.

Returns

T

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:342


groupBy()

groupBy(key)

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

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

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

Queryable<{items: T[];key: ReturnType<K>; }>

The result of the groupBy operation.

items

items: T[]

key

key: ReturnType<K>

Defined in

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

groupBy(key, result)

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

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

Queryable<R>

The queryable result of the groupBy operation.

Defined in

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


join()

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

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> | Queryable<S>The entity or query to join with.
conditionCThe join condition.

Returns

Queryable<JoinResult<Parameters<C>>>

The queryable result of the join operation.

Defined in

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


leftJoin()

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

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> | Queryable<S>The entity or query to join with.
conditionCThe join condition.

Returns

Queryable<JoinResult<Parameters<C>>>

The queryable result of the join operation.

Defined in

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


limit()

limit(limit: number): Queryable<T>

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

Parameters

ParameterTypeDescription
limitnumberThe number of elements to return.

Returns

Queryable<T>

The queryable result of the limit operation.

Defined in

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


max()

max(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): 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

number

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

Defined in

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


maybeFirst()

maybeFirst<P>(predicate?: P): 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 (obj: T, ...args: []) => boolean | (...args: readonly unknown[]) => boolean

Parameters

ParameterTypeDescription
predicate?PA function to test each element for a condition.

Returns

undefined | T

Defined in

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


maybeSingle()

maybeSingle<P>(predicate?: P): 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 (obj: T, ...args: []) => boolean | (...args: readonly unknown[]) => boolean

Parameters

ParameterTypeDescription
predicate?PA function to test each element for a condition.

Returns

undefined | T

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:378


min()

min(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): 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

number

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

Defined in

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


offset()

offset(offset: number): Queryable<T>

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

Parameters

ParameterTypeDescription
offsetnumberThe number of elements to skip.

Returns

Queryable<T>

The queryable result of the offset operation.

Defined in

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


orderBy()

orderBy<E>(expr: E): Queryable<T>

Sorts the elements of a sequence in ascending order.

Type Parameters

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

Parameters

ParameterTypeDescription
exprEA function to extract a sort key from an element.

Returns

Queryable<T>

The queryable result of the orderBy operation.

Defined in

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


orderByDesc()

orderByDesc<E>(expr: E): Queryable<T>

Sorts the elements of a sequence in descending order.

Type Parameters

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

Parameters

ParameterTypeDescription
exprEA function to extract a sort key from an element.

Returns

Queryable<T>

The queryable result of the orderByDesc operation.

Defined in

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


select()

select<P>(projector: P): Queryable<ReturnType<P>>

Projects each element of a sequence into a new form.

Type Parameters

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

Parameters

ParameterTypeDescription
projectorPA function that transforms the input element.

Returns

Queryable<ReturnType<P>>

The queryable result of the select operation.

Defined in

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


single()

single<P>(predicate?: P): T

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

Type Parameters

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

Parameters

ParameterTypeDescription
predicate?PA function to test each element for a condition.

Returns

T

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:365


sum()

sum(expr?: T extends JoinResult<K> ? (...args: readonly [K]) => number : (obj: T) => number): 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

number

The sum of the specified numerical expression for the sequence.

Defined in

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


where()

where<P>(predicate: P): Queryable<T>

Filters a sequence of values based on a predicate.

Type Parameters

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

Parameters

ParameterTypeDescription
predicatePA function to test each element for a condition.

Returns

Queryable<T>

The queryable result of the where operation.

Defined in

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


with()

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

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

Queryable<T>

The queryable result of the with operation.

Defined in

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