Skip to content

cozy-client / QueryDefinition

Class: QueryDefinition

Chainable API to create query definitions to retrieve documents from a Cozy. QueryDefinitions are sent to links.

Constructors

constructor

new QueryDefinition(options?)

Parameters

Name Type Description
options Object Initial options for the query definition
options.bookmark string -
options.cursor Cursor -
options.doctype string -
options.fields any[] -
options.id string -
options.ids any[] -
options.includes string[] -
options.indexedFields any[] -
options.limit number -
options.partialFilter any -
options.referenced string -
options.selector any -
options.skip number -
options.sort any[] -

Defined in

packages/cozy-client/src/queries/dsl.js:27

Properties

bookmark

bookmark: string

Defined in

packages/cozy-client/src/queries/dsl.js:60


cursor

cursor: Cursor

Defined in

packages/cozy-client/src/queries/dsl.js:59


doctype

doctype: string

Defined in

packages/cozy-client/src/queries/dsl.js:47


fields

fields: any[]

Defined in

packages/cozy-client/src/queries/dsl.js:51


id

id: string

Defined in

packages/cozy-client/src/queries/dsl.js:48


ids

ids: any[]

Defined in

packages/cozy-client/src/queries/dsl.js:49


includes

includes: string[]

Defined in

packages/cozy-client/src/queries/dsl.js:55


indexedFields

indexedFields: any[]

Defined in

packages/cozy-client/src/queries/dsl.js:52


limit

limit: number

Defined in

packages/cozy-client/src/queries/dsl.js:57


partialFilter

partialFilter: any

Defined in

packages/cozy-client/src/queries/dsl.js:53


referenced

referenced: string

Defined in

packages/cozy-client/src/queries/dsl.js:56


selector

selector: any

Defined in

packages/cozy-client/src/queries/dsl.js:50


skip

skip: number

Defined in

packages/cozy-client/src/queries/dsl.js:58


sort

sort: any[]

Defined in

packages/cozy-client/src/queries/dsl.js:54

Methods

UNSAFE_noLimit

UNSAFE_noLimit(): QueryDefinition

Returns

QueryDefinition

Defined in

packages/cozy-client/src/queries/dsl.js:235


checkSelector

checkSelector(selector): void

Checks the selector predicates.

It is useful to warn the developer when a partial index might be used.

Parameters

Name Type Description
selector any The selector definition

Returns

void

Defined in

packages/cozy-client/src/queries/dsl.js:108


checkSortOrder

checkSortOrder(__namedParameters): void

Checks if the sort order matches the index’ fields order.

When sorting with CouchDB, it is required to:

  • use indexed fields
  • keep the same order than the indexed fields.

See https://docs.cozy.io/en/tutorials/data/queries/#sort-data-with-mango

Parameters

Name Type
__namedParameters PartialQueryDefinition

Returns

void

Defined in

packages/cozy-client/src/queries/dsl.js:75


getById

getById(id): QueryDefinition

Query a single document on its id.

Parameters

Name Type Description
id string The document id.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:129


getByIds

getByIds(ids): QueryDefinition

Query several documents on their ids.

Parameters

Name Type Description
ids any[] The documents ids.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:142


include

include(includes): QueryDefinition

Includes documents having a relationships with the ones queried. For example, query albums including the photos.

Parameters

Name Type Description
includes any[] The documents to include.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:218


indexFields

indexFields(indexedFields): QueryDefinition

Specify which fields should be indexed. This prevent the automatic indexing of the mango fields.

Parameters

Name Type Description
indexedFields any[] The fields to index.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:175


limitBy

limitBy(limit): QueryDefinition

Maximum number of documents returned, useful for pagination. Default is 100.

Parameters

Name Type Description
limit number The document’s limit.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:231


offset

offset(skip): QueryDefinition

Skip the first ‘n’ documents, where ‘n’ is the value specified.

Beware, this performs badly on view’s index. Prefer cursor-based pagination in such situation.

Parameters

Name Type Description
skip number The number of documents to skip.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:248


offsetBookmark

offsetBookmark(bookmark): QueryDefinition

Use bookmark pagination. Note this only applies for mango-queries (not views) and is way more efficient than skip pagination. The bookmark is a string returned by the _find response and can be seen as a pointer in the index for the next query.

Parameters

Name Type Description
bookmark string The bookmark to continue a previous paginated query.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:286


offsetCursor

offsetCursor(cursor): QueryDefinition

Use cursor-based pagination. Warning: this is only useful for views. The cursor is a [startkey, startkey_docid] array, where startkey is the view’s key, e.g. [“io.cozy.photos.albums”, “album-id”] and startkey_docid is the id of the starting document of the query, e.g. “file-id”. Use the last docid of each query as startkey_docid to paginate or leave blank for the first query.

Parameters

Name Type Description
cursor Cursor The cursor for pagination.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:268


partialIndex

partialIndex(partialFilter): QueryDefinition

Specify a partial index. The filter must follow the same syntax than the selector.

A partial index includes a filter, used to select documents before the indexing. You can find more information about partial indexes here

Parameters

Name Type Description
partialFilter any The filter definition.

Returns

QueryDefinition

Defined in

packages/cozy-client/src/queries/dsl.js:189


referencedBy

referencedBy(document): QueryDefinition

Use the file reference system

Parameters

Name Type Description
document any The reference document

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:301


select

select(fields): QueryDefinition

Specify which fields of each object should be returned. If it is omitted, the entire object is returned.

Parameters

Name Type Description
fields any[] The fields to return.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:165


sortBy

sortBy(sort): QueryDefinition

Specify how to sort documents, following the sort syntax

Parameters

Name Type Description
sort any[] The list of field name and direction pairs.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:199


toDefinition

toDefinition(): Object

Returns

Object

Name Type
bookmark string
cursor Cursor
doctype string
fields any[]
id string
ids any[]
includes string[]
indexedFields any[]
limit number
partialFilter any
referenced string
selector any
skip number
sort any[]

Defined in

packages/cozy-client/src/queries/dsl.js:305


where

where(selector): QueryDefinition

Query documents with a mango selector. Each field passed in the selector will be indexed, except if the indexField option is used.

Parameters

Name Type Description
selector any The Mango selector.

Returns

QueryDefinition

The QueryDefinition object.

Defined in

packages/cozy-client/src/queries/dsl.js:153