Query
sourceSpecifies a query.
A query specification consists of six parts: a source model, joins, filter predicates, sort predicates, a set of fields to select, and whether to include or exclude deleted records.
Source model
This is the total domain of input records to consider.
For simplicity, in this API, the source of a query is always a model, rather than another query. However, it wouldn't be too difficult to relax this in the future, since the implementation already operates on a source query (the base view of the nominated model).
Joins
A query may have any number of joins defined. These can alter the domain of records under consideration, as well as add extra fields to the resultset.
See JoinSpec for details about what kinds of join are supported.
Filter
This is the representation of the where clause of the query. Each filter predicate is represented using a structure that defines an operator and one or more operands. For most predicates the operand is a field of the input domain of the query, which is the total set of fields before it is constrained by the select clause.
See FilterPredicate for details about what kinds of predicate are supported.
Sort
This is the representation of the 'order by' clause of the query. Each sort predicate consists of an order (ascending or descending) and the name of a field upon which to sort. As for filter predicates, the domain of fields is the total set of fields.
If no sort order is given, the result is sorted in primary key order.
See SortPredicate for more details.
Deleted records
By default, deleted records are included. The caller can choose to have deleted records excluded. The exclusion is applied to the base model and any foreign models joined via foreign keys; it does not apply to subquery joins, where the caller can choose whether or not to exclude deleted foreign records on a per-subquery level.
Constructors
new Query<T extends Model<string, T> = Model<string>>(model: ModelType<T>, joins: JoinSpec[] = [], filter: FilterPredicate[] = [], sort: SortPredicate[] = []): Querysource
Properties
filter: FilterPredicate[]source
Filter predicates to reduce the resultset. These can refer to joined fields.
implements
QueryMetadata.joins
Join specifications for adding columns from other models.
model: ModelType<T>source
implements
QueryMetadata.model
The primary source model for the query.
sort: SortPredicate[]source
Sort predicates to order the resultset. These can refer to joined fields.
Methods
Static methods
isModelType(value: any): undefined | ModelType<Model<string>>source
validateHook<K extends keyof Query<Model<string>>>(field: K, item: Query, tracer: Tracer): undefined | Maybe<Query<Model<string>>[K]>source
Instance methods
as<U extends Model<string, U>>(): Querysource
getFromClause(): stringsource
getJoinClauses(): string[]source
getOrderByClauses(): string[]source
getWhereClauses(): string[]source
implements
Hashable.toHash
toJSON(): objectsource
toString(): stringsource
Inherited methods
applyFieldGuards<T>(target: AbstractCtor<T>, item: any, tracer: Tracer): Maybe<T>source
inherited from
ValidatableType.applyFieldGuards
validate<T extends ValidatableType<T>>(this: AbstractCtor<T> & CanHaveValidateHook<T>, item: any, tracer: Tracer = ...): Maybe<T>source
inherited from
ValidatableType.validate
withFields<T extends FieldDict>(fields: T): Validatable<MaterialisedType<T>> & Ctor<MaterialisedType<T>>source
inherited from
ValidatableType.withFields