cozy-client / QueryDefinition
Class: QueryDefinition¶
Chainable API to create query definitions to retrieve documents
from a Cozy. QueryDefinition
s 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 |
CouchDBViewCursor |
- |
options.doctype |
string |
- |
options.fields |
string [] |
- |
options.id |
string |
- |
options.ids |
string [] |
- |
options.includes |
string [] |
- |
options.indexedFields |
string [] |
- |
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:50
Properties¶
bookmark¶
• bookmark: string
Defined in
packages/cozy-client/src/queries/dsl.js:64
cursor¶
• cursor: CouchDBViewCursor
Defined in
packages/cozy-client/src/queries/dsl.js:63
doctype¶
• doctype: string
Defined in
packages/cozy-client/src/queries/dsl.js:51
fields¶
• fields: string
[]
Defined in
packages/cozy-client/src/queries/dsl.js:55
id¶
• id: string
Defined in
packages/cozy-client/src/queries/dsl.js:52
ids¶
• ids: string
[]
Defined in
packages/cozy-client/src/queries/dsl.js:53
includes¶
• includes: string
[]
Defined in
packages/cozy-client/src/queries/dsl.js:59
indexedFields¶
• indexedFields: string
[]
Defined in
packages/cozy-client/src/queries/dsl.js:56
limit¶
• limit: number
Defined in
packages/cozy-client/src/queries/dsl.js:61
partialFilter¶
• partialFilter: any
Defined in
packages/cozy-client/src/queries/dsl.js:57
referenced¶
• referenced: string
Defined in
packages/cozy-client/src/queries/dsl.js:60
selector¶
• selector: any
Defined in
packages/cozy-client/src/queries/dsl.js:54
skip¶
• skip: number
Defined in
packages/cozy-client/src/queries/dsl.js:62
sort¶
• sort: any
[]
Defined in
packages/cozy-client/src/queries/dsl.js:58
Methods¶
UNSAFE_noLimit¶
▸ UNSAFE_noLimit(): QueryDefinition
Returns
Defined in
packages/cozy-client/src/queries/dsl.js:291
checkSelectFields¶
▸ checkSelectFields(obj
): void
Check if the selected fields are all included in the selectors
Parameters
Name | Type | Description |
---|---|---|
obj |
PartialQueryDefinition |
A partial QueryDefinition to check |
Returns
void
Defined in
packages/cozy-client/src/queries/dsl.js:154
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:117
checkSortOrder¶
▸ checkSortOrder(obj
): 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 | Description |
---|---|---|
obj |
PartialQueryDefinition |
A partial QueryDefinition to check |
Returns
void
Defined in
packages/cozy-client/src/queries/dsl.js:78
getById¶
▸ getById(id
): QueryDefinition
Query a single document on its id.
Parameters
Name | Type | Description |
---|---|---|
id |
string |
The document id. |
Returns
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:181
getByIds¶
▸ getByIds(ids
): QueryDefinition
Query several documents on their ids.
Parameters
Name | Type | Description |
---|---|---|
ids |
any [] |
The documents ids. |
Returns
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:194
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:274
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:230
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:287
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:304
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:342
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 |
CouchDBViewCursor |
The cursor for pagination. |
Returns
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:324
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
Defined in
packages/cozy-client/src/queries/dsl.js:244
referencedBy¶
▸ referencedBy(document
): QueryDefinition
Use the file reference system
Parameters
Name | Type | Description |
---|---|---|
document |
any |
The reference document |
Returns
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:357
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:218
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
The QueryDefinition object.
Defined in
packages/cozy-client/src/queries/dsl.js:255
toDefinition¶
▸ toDefinition(): Object
Returns
Object
Name | Type |
---|---|
bookmark |
string |
cursor |
CouchDBViewCursor |
doctype |
string |
fields |
string [] |
id |
string |
ids |
string [] |
includes |
string [] |
indexedFields |
string [] |
limit |
number |
partialFilter |
any |
referenced |
string |
selector |
any |
skip |
number |
sort |
any [] |
Defined in
packages/cozy-client/src/queries/dsl.js:361
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
The QueryDefinition object.
Defined in