6.5 KiB
Index
Indexes on field names, with atomic operations and which can optionally enforce a unique constraint or allow indexed fields to be undefined
Kind: global class
- Index
- new Index(options)
- .fieldName :
string
- .unique :
boolean
- .sparse :
boolean
- .treeOptions :
Object
- .tree :
AVLTree
- .reset([newData])
- .insert(doc)
- .remove(doc)
- .update(oldDoc, [newDoc])
- .revertUpdate(oldDoc, [newDoc])
- .getMatching(value) ⇒
Array.<document>
- .getBetweenBounds(query) ⇒
Array.<document>
- .getAll() ⇒
Array.<document>
new Index(options)
Create a new index All methods on an index guarantee that either the whole operation was successful and the index changed or the operation was unsuccessful and an error is thrown while the index is unchanged
Params
- options
object
- .fieldName
string
-On which field should the index apply (can use dot notation to index on sub fields)
- [.unique]
boolean
= false
-Enforces a unique constraint
- [.sparse]
boolean
= false
-Allows a sparse index (we can have documents for which fieldName is
undefined
)
- .fieldName
index.fieldName : string
On which field the index applies to (may use dot notation to index on sub fields).
Kind: instance property of Index
index.unique : boolean
Defines if the index enforces a unique constraint for this index.
Kind: instance property of Index
index.sparse : boolean
Defines if we can have documents for which fieldName is undefined
Kind: instance property of Index
index.treeOptions : Object
Options object given to the underlying BinarySearchTree.
Kind: instance property of Index
index.tree : AVLTree
Underlying BinarySearchTree for this index. Uses an AVLTree for optimization.
Kind: instance property of Index
index.reset([newData])
Reset an index
Kind: instance method of Index
Params
- [newData]
document
|?Array.<document>
-Data to initialize the index with. If an error is thrown during insertion, the index is not modified.
index.insert(doc)
Insert a new document in the index If an array is passed, we insert all its elements (if one insertion fails the index is not modified) O(log(n))
Kind: instance method of Index
Params
- doc
document
|Array.<document>
-The document, or array of documents, to insert.
index.remove(doc)
Removes a document from the index. If an array is passed, we remove all its elements The remove operation is safe with regards to the 'unique' constraint O(log(n))
Kind: instance method of Index
Params
- doc
Array.<document>
|document
-The document, or Array of documents, to remove.
index.update(oldDoc, [newDoc])
Update a document in the index If a constraint is violated, changes are rolled back and an error thrown Naive implementation, still in O(log(n))
Kind: instance method of Index
Params
- oldDoc
document
|Array.<{oldDoc: document, newDoc: document}>
-Document to update, or an
Array
of{oldDoc, newDoc}
pairs. - [newDoc]
document
-Document to replace the oldDoc with. If the first argument is an
Array
of{oldDoc, newDoc}
pairs, this second argument is ignored.
index.revertUpdate(oldDoc, [newDoc])
Revert an update
Kind: instance method of Index
Params
- oldDoc
document
|Array.<{oldDoc: document, newDoc: document}>
-Document to revert to, or an
Array
of{oldDoc, newDoc}
pairs. - [newDoc]
document
-Document to revert from. If the first argument is an Array of {oldDoc, newDoc}, this second argument is ignored.
index.getMatching(value) ⇒ Array.<document>
Get all documents in index whose key match value (if it is a Thing) or one of the elements of value (if it is an array of Things)
Kind: instance method of Index
Params
- value
Array.<*>
|*
-Value to match the key against
index.getBetweenBounds(query) ⇒ Array.<document>
Get all documents in index whose key is between bounds are they are defined by query Documents are sorted by key
Kind: instance method of Index
Params
- query
object
-An object with at least one matcher among $gt, $gte, $lt, $lte.
- [.$gt]
*
-Greater than matcher.
- [.$gte]
*
-Greater than or equal matcher.
- [.$lt]
*
-Lower than matcher.
- [.$lte]
*
-Lower than or equal matcher.
- [.$gt]
index.getAll() ⇒ Array.<document>
Get all elements in the index
Kind: instance method of Index