Query

  1. Properties
    1. ready – boolean
    2. results – Array
    3. extra – Object
  2. Methods
    1. destroy()
  3. Events
    1. 'ready'
    2. 'changed'
    3. 'insert'
    4. 'move'
    5. 'remove'
    6. 'extra'
    7. 'error'

Representation of a query made through connection.createFetchQuery() or connection.createSubscribeQuery().

Properties

ready – boolean

Represents if results are ready and available in results

results – Array

Query results, as an array of Doc instances

extra – Object

Extra query results that are not an array of Docs. Available for certain database adapters and queries

Methods

destroy()

Unsubscribe and stop firing events.

query.destroy([callback])

callback – Function

Optional

function(error) { ... }

A callback that will be called when the query has been destroyed

Events

This class extends EventEmitter, and can be used with the normal methods such as on() and off().

'ready'

The initial query results were loaded from the server. Triggered on connection.createFetchQuery() or connection.createSubscribeQuery().

query.on('ready', function() { ... })

'changed'

The subscribed query results have changed. Fires only after a sequence of diffs are handled.

query.on('changed', function(results) { ... })

results – Array

Query results, as an array of Doc instances

'insert'

A contiguous sequence of documents were added to the query results array.

query.on('insert', function(docs, index) { ... })

docs – Array

Array of inserted Docs

index – number

The index at which the documents were inserted

'move'

A contiguous sequence of documents moved position in the query results array.

query.on('move', function(docs, from, to) { ... })

docs – Array

Array of moved Docs

from – number

The index the documents were moved from

to – number

The index the documents were moved to

'remove'

A contiguous sequence of documents were removed from the query results array.

query.on('remove', function(docs, index) { ... })

docs – Array

Array of removed Docs

index – number

The index at which the documents were removed

'extra'

The extra property was changed.

query.on('extra', function(extra) { ... })

extra – Object

The updated extra value

'error'

There was an error receiving updates to a subscription.

query.on('error', function(error) { ... })

errorShareDBError

The error that occurred