Redux-ORM

Redux-ORM

  • Getting Started
  • Docs
  • API
  • GitHub

›API Reference

Introduction

  • Getting Started
  • Installation

Basics

  • Quick Start
  • Relational Fields
  • Reducers
  • Selectors
  • Usage with React

Advanced

  • Complex Selectors
  • Custom Reducer

API Reference

  • API Reference
  • ORM
  • Model
  • QuerySet
  • Session
  • Fields
  • Redux

QuerySet

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

  • QuerySet
    • new QuerySet(modelClass, clauses, [opts])
    • withModels
    • withRefs
    • toRefArray() ⇒ Array.
    • toModelArray() ⇒ Array.
    • count() ⇒ number
    • exists() ⇒ Boolean
    • at(index) ⇒ Model ⎮ undefined
    • first() ⇒ Model
    • last() ⇒ Model
    • all() ⇒ QuerySet
    • filter(lookupObj) ⇒ QuerySet
    • exclude(lookupObj) ⇒ QuerySet
    • orderBy(iteratees, [orders]) ⇒ QuerySet
    • update(mergeObj) ⇒ undefined
    • delete() ⇒ undefined
    • map()
    • forEach()

new QuerySet(modelClass, clauses, [opts])

Creates a QuerySet. The constructor is mainly for internal use;
You should access QuerySet instances from [Model](Model).

ParamTypeDescription
modelClassModel

the model class of objects in this QuerySet.

clausesArray.

query clauses needed to evaluate the set.

[opts]Object

additional options

withModels

Deprecated

Kind: instance property of QuerySet

withRefs

Deprecated

Kind: instance property of QuerySet

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 of QuerySet
Returns: Array. -

references to the plain JS objects represented by
the QuerySet

toModelArray()⇒ Array.<Model>

Returns an array of [Model](Model) instances represented by the QuerySet.

Kind: instance method of QuerySet
Returns: Array. -

model instances represented by the QuerySet

count()⇒ number

Returns the number of [Model](Model) instances represented by the QuerySet.

Kind: instance method of QuerySet
Returns: number -

length of the QuerySet

exists()⇒ Boolean

Checks if the [QuerySet](#QuerySet) instance has any records matching the query
in the database.

Kind: instance method of QuerySet
Returns: Boolean -

true if the QuerySet instance contains entities, else false.

at(index)⇒ Model,undefined

Returns the [Model](Model) instance at index index in the [QuerySet](#QuerySet) instance if
withRefs flag is set to false, or a reference to the plain JavaScript
object in the model state if true.

Kind: instance method of QuerySet
Returns: Model ⎮ undefined -

a Model instance at index
index in the QuerySet instance,
or undefined if the index is out of bounds.

ParamTypeDescription
indexnumber

index of the model instance to get

first()⇒ Model

Returns the [Model](Model) instance at index 0 in the [QuerySet](#QuerySet) instance.

Kind: instance method of QuerySet

last()⇒ Model

Returns the [Model](Model) instance at index QuerySet.count() - 1

Kind: instance method of QuerySet

all()⇒ QuerySet

Returns a new [QuerySet](#QuerySet) instance with the same entities.

Kind: instance method of QuerySet
Returns: QuerySet -

a new QuerySet with the same entities.

filter(lookupObj)⇒ QuerySet

Returns a new [QuerySet](#QuerySet) instance with entities that match properties in lookupObj.

Kind: instance method of QuerySet
Returns: QuerySet -

a new QuerySet instance with objects that passed the filter.

ParamTypeDescription
lookupObjObject

the properties to match objects with. Can also be a function.
It works the same as Lodash filter.

exclude(lookupObj)⇒ QuerySet

Returns a new [QuerySet](#QuerySet) instance with entities that do not match
properties in lookupObj.

Kind: instance method of QuerySet
Returns: QuerySet -

a new QuerySet instance with objects that did not pass the filter.

ParamTypeDescription
lookupObjObject

the properties to unmatch objects with. Can also be a function.
It works the same as Lodash reject.

orderBy(iteratees, [orders])⇒ QuerySet

Returns a new [QuerySet](#QuerySet) instance with entities ordered by iteratees in ascending
order, unless otherwise specified. Delegates to Lodash orderBy.

Kind: instance method of QuerySet
Returns: QuerySet -

a new QuerySet with objects ordered by iteratees.

ParamTypeDescription
iterateesArray. ⎮ Array.<function()>

an array where each item can be a string or a
function. If a string is supplied, it should
correspond to property on the entity that will
determine the order. If a function is supplied,
it should return the value to order by.

[orders]Array.<(Boolean'asc''desc')>

the sort orders of iteratees. If unspecified, all iteratees
will be sorted in ascending order. true and 'asc'
correspond to ascending order, and false and 'desc'
to descending order.

update(mergeObj)⇒ undefined

Records an update specified with mergeObj to all the objects
in the [QuerySet](#QuerySet) instance.

Kind: instance method of QuerySet

ParamTypeDescription
mergeObjObject

an object to merge with all the objects in this
queryset.

delete()⇒ undefined

Records a deletion of all the objects in this [QuerySet](#QuerySet) instance.

Kind: instance method of QuerySet

map()

Deprecated

Kind: instance method of QuerySet

forEach()

Deprecated

Kind: instance method of QuerySet

Last updated on 10.1.2020
← ModelSession →
  • new QuerySet(modelClass, clauses, [opts])
  • withModels
  • withRefs
  • toRefArray()⇒ Array.<Object>
  • toModelArray()⇒ Array.<Model>
  • count()⇒ number
  • exists()⇒ Boolean
  • at(index)⇒ Model,undefined
  • first()⇒ Model
  • last()⇒ Model
  • all()⇒ QuerySet
  • filter(lookupObj)⇒ QuerySet
  • exclude(lookupObj)⇒ QuerySet
  • orderBy(iteratees, [orders])⇒ QuerySet
  • update(mergeObj)⇒ undefined
  • delete()⇒ undefined
  • map()
  • forEach()
Redux-ORM
Docs
Getting StartedQuick StartAdvanced scenarios
Community
Stack OverflowGitter
More
GitHubStar
Copyright © 2020 Redux-ORM documentation authors.
Some icons copyright Font Awesome.