Home Reference Source
public class | source

PreparedQuery

Class that presents a simple interface for constructing queries for a relational database using a model map object describing the connections between models.

All methods except exec are chainable.

Constructor Summary

Public Constructor
public

constructor(modelId: String, models: JoinJsMap, knex: KnexInstance)

Generally, this shouldn't be called by external code. This object is generated by the main interface when the generateQueryFor method is used.

Member Summary

Public Members
public

knex: *

public

modelId: *

public

models: *

public
public

populated: *[]

public
public

sortDir: *

public

Method Summary

Public Methods
public

Run the query and construct a nested JS object representation of it.

public

limit(value: Number): *

Define the maximum number of elements to return (useful for pagination).

public

populate(name: String): *

Populate the joins for a collection or association of the primary model of the query.

public

skip(value: Number): *

Define the number of elements to skip (useful for pagination).

public

sort(attr: String, dir: String): *

Define the ordering of the results

public

where(clauses: Object | Array): *

Define a restriction on the result set.

Public Constructors

public constructor(modelId: String, models: JoinJsMap, knex: KnexInstance) source

Generally, this shouldn't be called by external code. This object is generated by the main interface when the generateQueryFor method is used.

Params:

NameTypeAttributeDescription
modelId String

The primary model to query

models JoinJsMap

The complete schema of the database (after internal processing)

knex KnexInstance

A knex instance

Public Members

public knex: * source

public modelId: * source

public models: * source

public originalModel: * source

public populated: *[] source

public sortAttr: * source

public sortDir: * source

public whereClauses: *[] source

Public Methods

public exec(): Promise source

Run the query and construct a nested JS object representation of it.

Return:

Promise

A promise that resolves to the result of the query

public limit(value: Number): * source

Define the maximum number of elements to return (useful for pagination).

Params:

NameTypeAttributeDescription
value Number

The maximum number of elements to return

Return:

*

public populate(name: String): * source

Populate the joins for a collection or association of the primary model of the query.

Params:

NameTypeAttributeDescription
name String

The name property of the association or collection

Return:

*

public skip(value: Number): * source

Define the number of elements to skip (useful for pagination).

Params:

NameTypeAttributeDescription
value Number

The number of elements to skip

Return:

*

public sort(attr: String, dir: String): * source

Define the ordering of the results

Params:

NameTypeAttributeDescription
attr String

The column name to sort based on

dir String

The direction of the sorting. Must be asc or desc.

Return:

*

public where(clauses: Object | Array): * source

Define a restriction on the result set.

Params:

NameTypeAttributeDescription
clauses Object | Array

An object (or list of objects) specifying the predicate that all results must satisfy. Multiple calls to this function on a single prepared query instance will be appended to the list of clauses that are combined using boolean AND logic (ie. results must satisfy all predicates in the list)

Each predicate consists of a `key` (the column name) and a `value` or `values`
list. If a list of values is specifed it is interpreted as a WhereIn operation
such that results can match ANY of the values supplied.

Return:

*