This class is used to build and make queries to the database
and operating the resulting set (such as updating attributes
or deleting the records).
The queries are built lazily. For example:
const qs = Book.all() .filter(book => book.releaseYear > 1999) .orderBy('name');Doesn't execute a query. The query is executed only when
you need information from the query result, such as [count](#QuerySet+count),
[toRefArray](#QuerySet+toRefArray). After the query is executed, the resulting
set is cached in the QuerySet instance.
QuerySet instances also return copies, so chaining filters doesn't
mutate the previous instances.
Kind: global class
new QuerySet(modelClass, clauses, [opts])withModelswithRefstoRefArray() ⇒ Array.toModelArray() ⇒ Array.count() ⇒ numberexists() ⇒ Booleanat(index) ⇒ Model ⎮ undefinedfirst() ⇒ Modellast() ⇒ Modelall() ⇒ QuerySetfilter(lookupObj) ⇒ QuerySetexclude(lookupObj) ⇒ QuerySetorderBy(iteratees, [orders]) ⇒ QuerySetupdate(mergeObj) ⇒ undefineddelete() ⇒ undefinedmap()forEach()new QuerySet(modelClass, clauses, [opts])Creates a QuerySet. The constructor is mainly for internal use;
You should access QuerySet instances from [Model](Model).
| Param | Type | Description |
|---|---|---|
| modelClass | Model | the model class of objects in this QuerySet. |
| clauses | Array. | query clauses needed to evaluate the set. |
| [opts] | Object | additional options |
withModelsDeprecated
Kind: instance property ofQuerySet
withRefsDeprecated
Kind: instance property ofQuerySet
toRefArray()⇒ Array.<Object>Returns an array of the plain objects represented by the QuerySet.
The plain objects are direct references to the store.
Kind: instance method ofQuerySet
Returns: Array.
toModelArray()⇒ Array.<Model>Returns an array of [Model](Model) instances represented by the QuerySet.
Kind: instance method ofQuerySet model instances represented by the QuerySet
Returns: Array.
count()⇒ numberReturns the number of [Model](Model) instances represented by the QuerySet.
Kind: instance method ofQuerySet
Returns: number -
length of the QuerySet
exists()⇒ BooleanChecks if the [QuerySet](#QuerySet) instance has any records matching the query
in the database.
Kind: instance method ofQuerySet
Returns: Boolean -
true if theQuerySet instance contains entities, elsefalse.
at(index)⇒ Model,undefinedReturns the [Model](Model) instance at indexindex in the [QuerySet](#QuerySet) instance ifwithRefs flag is set tofalse, or a reference to the plain JavaScript
object in the model state iftrue.
Kind: instance method ofQuerySet
Returns:Model ⎮ undefined -
aModel instance at indexindex in theQuerySet instance,
or undefined if the index is out of bounds.
| Param | Type | Description |
|---|---|---|
| index | number | index of the model instance to get |
first()⇒ ModelReturns the [Model](Model) instance at index 0 in the [QuerySet](#QuerySet) instance.
Kind: instance method ofQuerySet
last()⇒ ModelReturns the [Model](Model) instance at indexQuerySet.count() - 1
Kind: instance method ofQuerySet
all()⇒ QuerySetReturns a new [QuerySet](#QuerySet) instance with the same entities.
Kind: instance method ofQuerySet
Returns:QuerySet -
a new QuerySet with the same entities.
filter(lookupObj)⇒ QuerySetReturns a new [QuerySet](#QuerySet) instance with entities that match properties inlookupObj.
Kind: instance method ofQuerySet
Returns:QuerySet -
a newQuerySet instance with objects that passed the filter.
| Param | Type | Description |
|---|---|---|
| lookupObj | Object | the properties to match objects with. Can also be a function. |
exclude(lookupObj)⇒ QuerySetReturns a new [QuerySet](#QuerySet) instance with entities that do not match
properties inlookupObj.
Kind: instance method ofQuerySet
Returns:QuerySet -
a newQuerySet instance with objects that did not pass the filter.
| Param | Type | Description |
|---|---|---|
| lookupObj | Object | the properties to unmatch objects with. Can also be a function. |
orderBy(iteratees, [orders])⇒ QuerySetReturns a new [QuerySet](#QuerySet) instance with entities ordered byiteratees in ascending
order, unless otherwise specified. Delegates toLodash orderBy.
Kind: instance method ofQuerySet
Returns:QuerySet -
a newQuerySet with objects ordered byiteratees.
| Param | Type | Description | ||
|---|---|---|---|---|
| iteratees | Array. | an array where each item can be a string or a | ||
| [orders] | Array.<(Boolean | 'asc' | 'desc')> | the sort orders of |
update(mergeObj)⇒ undefinedRecords an update specified withmergeObj to all the objects
in the [QuerySet](#QuerySet) instance.
Kind: instance method ofQuerySet
| Param | Type | Description |
|---|---|---|
| mergeObj | Object | an object to merge with all the objects in this |
delete()⇒ undefinedRecords a deletion of all the objects in this [QuerySet](#QuerySet) instance.
Kind: instance method ofQuerySet
map()Deprecated
Kind: instance method ofQuerySet
forEach()Deprecated
Kind: instance method ofQuerySet