Query
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
Doc
s. 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
Doc
s
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
Doc
s
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
Doc
s
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) { ... })
error
– ShareDBError
The error that occurred