Home Manual Reference Source Test
import ModelQuery from 'electron-coresqlite/lib/query.js'
public class | source

ModelQuery

ModelQuery exposes an ActiveRecord-style syntax for building database queries that return models and model counts. Model queries are returned from the factory methods {RxDatabase::find}, {RxDatabase::findBy}, {RxDatabase::findAll}, and {RxDatabase::count}, and are the primary interface for retrieving data from the app's local cache.

ModelQuery does not allow you to modify the local cache. To create, update or delete items from the local cache, see {RxDatabase::inTransaction} and {DatabaseTransaction::persistModel}.

Simple Example:* Fetch a thread

const query = db.find(Thread, '123a2sc1ef4131');
query.then((thread) {
// thread or null
});

Advanced Example:* Fetch 50 threads in the inbox, in descending order

const query = db.findAll(Thread);
query.where([Thread.attributes.categories.contains('label-id')])
.order([Thread.attributes.lastMessageReceivedTimestamp.descending()])
.limit(100).offset(50)
.then((threads) {
// array of threads
});

Constructor Summary

Public Constructor
public

constructor(class: Model, database: RxDatabase)

Method Summary

Public Methods
public

clone(): Query

public

count(): *

Set the count flag - instead of returning inflated models, the query will return the result COUNT.

public

distinct(): *

public

finalize(): *

public

formatResult(inflated: *): *

public

idsOnly(): *

public

Include specific joined data attributes in result objects.

public

includeAll(): *

Include all of the available joined data attributes in returned models.

public

inflateResult(result: *): *

public

limit(limit: Number): *

Limit the number of query results.

public
public

matchers(): *

public
public
public

observe(objectPattern: {"allowQueryChanges": *, "name": *}): *

public

offset(offset: Number): *

public

one(): *

Set the singular flag - only one model will be returned from the query, and a LIMIT 1 clause will be used.

public

order(ordersOrOrder: Array): *

Apply a sort order to the query.

public
public

page(start: *, end: *, pageSize: number, pagePadding: number): *

A convenience method for setting both limit and offset given a desired page size.

public

range(): *

public
public

search(query: *): *

public

sql(): String

public

then(next: *): Promise

Short-hand syntax that calls run().then(fn) with the provided function.

public

where(matchers: Array): *

Add one or more where clauses to the query This method is chainable.

public

whereAny(matchers: *): *

Public Constructors

public constructor(class: Model, database: RxDatabase) source

Params:

NameTypeAttributeDescription
class Model

A {Model} class to query

database RxDatabase
  • optional

An optional reference to a {RxDatabase} the query will be executed on.

Public Methods

public clone(): Query source

Return:

Query

A deep copy of the Query that can be modified.

public count(): * source

Set the count flag - instead of returning inflated models, the query will return the result COUNT.

This method is chainable.

Return:

*

public distinct(): * source

Return:

*

public finalize(): * source

Return:

*

public formatResult(inflated: *): * source

Params:

NameTypeAttributeDescription
inflated *

Return:

*

public idsOnly(): * source

Return:

*

public include(attr: AttributeJoinedData): * source

Include specific joined data attributes in result objects.

Params:

NameTypeAttributeDescription
attr AttributeJoinedData

Attribute that you want to be populated in the returned models. Note: This results in a LEFT OUTER JOIN. See {AttributeJoinedData} for more information.

This method is chainable.

Return:

*

public includeAll(): * source

Include all of the available joined data attributes in returned models.

This method is chainable.

Return:

*

public inflateResult(result: *): * source

Params:

NameTypeAttributeDescription
result *

Return:

*

public limit(limit: Number): * source

Limit the number of query results.

Params:

NameTypeAttributeDescription
limit Number

The number of models that should be returned.

This method is chainable.

Return:

*

public matcherValueForModelKey(key: *): * source

Params:

NameTypeAttributeDescription
key *

Return:

*

public matchers(): * source

Return:

*

public matchersFlattened(): * source

Return:

*

public objectClass(): * source

Return:

*

public observe(objectPattern: {"allowQueryChanges": *, "name": *}): * source

Params:

NameTypeAttributeDescription
objectPattern {"allowQueryChanges": *, "name": *}
  • optional
  • default: {}

Return:

*

public offset(offset: Number): * source

Params:

NameTypeAttributeDescription
offset Number

The start offset of the query. This method is chainable.

Return:

*

public one(): * source

Set the singular flag - only one model will be returned from the query, and a LIMIT 1 clause will be used.

This method is chainable.

Return:

*

public order(ordersOrOrder: Array): * source

Apply a sort order to the query.

Params:

NameTypeAttributeDescription
ordersOrOrder Array

An {Array} of one or more {SortOrder} objects that determine the sort order of returned models.

This method is chainable.

Return:

*

public orderSortDescriptors(): * source

Return:

*

public page(start: *, end: *, pageSize: number, pagePadding: number): * source

A convenience method for setting both limit and offset given a desired page size.

Params:

NameTypeAttributeDescription
start *
end *
pageSize number
  • optional
  • default: 50
pagePadding number
  • optional
  • default: 100

Return:

*

public range(): * source

Return:

*

public run(): Promise source

Return:

Promise

A Promise that resolves with the Models returned by the query, or rejects with an error from the Database layer.

Params:

NameTypeAttributeDescription
query *

Return:

*

public sql(): String source

Return:

String

The SQL generated for the query.

public then(next: *): Promise source

Short-hand syntax that calls run().then(fn) with the provided function.

Params:

NameTypeAttributeDescription
next *

Return:

Promise

A promise that resolves with the Models returned by the query, or rejects with an error from the Database layer.

public where(matchers: Array): * source

Add one or more where clauses to the query This method is chainable.

Params:

NameTypeAttributeDescription
matchers Array

Array of {Matcher} objects that add where clauses to the underlying query.

Return:

*

public whereAny(matchers: *): * source

Params:

NameTypeAttributeDescription
matchers *

Return:

*