new Loki(filename, optionsopt)
Loki: The main database class
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
filename |
string | name of the file to be saved to |
|||||||||||||||||||||||||
options |
object |
<optional> |
(Optional) config options object Properties
|
- Implements:
- Source:
Methods
addCollection(name, optionsopt) → {Collection}
Adds a collection to the database.
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
name |
string | name of collection to add |
|||||||||||||||||||||||||||||||
options |
object |
<optional> |
(optional) options to configure collection with. Properties
|
Returns:
a reference to the collection which was just added
- Type
- Collection
anonym(docs, options) → {Collection}
Shorthand method for quickly creating and populating an anonymous collection. This collection is not referenced internally so upon losing scope it will be garbage collected.
Parameters:
Name | Type | Description |
---|---|---|
docs |
Array | document array to initialize the anonymous collection with |
options |
object | configuration object, see Loki#addCollection options |
Returns:
New collection which you can query or chain
- Type
- Collection
Example
var results = new loki().anonym(myDocArray).find({'age': {'$gt': 30} });
clearChanges()
(Changes API) : clears all the changes in all collections.
close(callbackopt)
Emits the close event. In autosave scenarios, if the database is dirty, this will save and disable timer. Does not actually destroy the db.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function |
<optional> |
(Optional) if supplied will be registered with close event before emitting. |
configureOptions(options, initialConfig)
Allows reconfiguring database options
Parameters:
Name | Type | Description | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
object | configuration options to apply to loki db object Properties
|
||||||||||||||||||||||||
initialConfig |
boolean | (internal) true is passed when loki ctor is invoking |
deleteDatabase(options, callbackopt)
Handles deleting a database from file system, local storage, or adapter (indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object | not currently used (remove or allow overrides?) |
|
callback |
function |
<optional> |
(Optional) user supplied async callback / error handler |
generateChangesNotification(optionalopt) → {array}
(Changes API) : takes all the changes stored in each collection and creates a single array for the entire database. If an array of names of collections is passed then only the included collections will be tracked.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
optional |
array |
<optional> |
array of collection names. No arg means all collections are processed. |
Returns:
array of changes
- Type
- array
getCollection(collectionName) → {Collection}
Retrieves reference to a collection by name.
Parameters:
Name | Type | Description |
---|---|---|
collectionName |
string | name of collection to look up |
Returns:
Reference to collection in database by that name, or null if not found
- Type
- Collection
loadDatabase(options, callbackopt)
Handles loading from file system, local storage, or adapter (indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
object | not currently used (remove or allow overrides?) |
|
callback |
function |
<optional> |
(Optional) user supplied async callback / error handler |
loadJSON(serializedDb, options)
Inflates a loki database from a serialized JSON string
Parameters:
Name | Type | Description |
---|---|---|
serializedDb |
string | a serialized loki database string |
options |
object | apply or override collection level settings |
loadJSONObject(dbObject, options)
Inflates a loki database from a JS object
Parameters:
Name | Type | Description |
---|---|---|
dbObject |
object | a serialized loki database string |
options |
object | apply or override collection level settings |
removeCollection(collectionName)
Removes a collection from the database.
Parameters:
Name | Type | Description |
---|---|---|
collectionName |
string | name of collection to remove |
saveDatabase(callbackopt)
Handles saving to file system, local storage, or adapter (indexeddb) This method utilizes loki configuration options (if provided) to determine which persistence method to use, or environment detection (if configuration was not provided).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
callback |
function |
<optional> |
(Optional) user supplied async callback / error handler |
serialize() → {string}
Serialize database to a string which can be loaded via Loki#loadJSON
Returns:
Stringified representation of the loki database.
- Type
- string
serializeChanges() → {string}
(Changes API) - stringify changes for network transmission
Returns:
string representation of the changes
- Type
- string