Class: LokiIndexedAdapter

LokiIndexedAdapter(appname)

new LokiIndexedAdapter(appname)

Loki persistence adapter class for indexedDb. This class fulfills abstract adapter interface which can be applied to other storage methods. Utilizes the included LokiCatalog app/key/value database for actual database persistence. Indexeddb is highly async, but this adapter has been made 'console-friendly' as well. Anywhere a callback is omitted, it should return results (if applicable) to console. IndexedDb storage is provided per-domain, so we implement app/key/value database to allow separate contexts for separate apps within a domain.

Parameters:
Name Type Description
appname string

(Optional) Application name context can be used to distinguish subdomains, 'loki' by default

Source:
Example
var idbAdapter = new LokiIndexedAdapter('finance');

Methods

checkAvailability() → {boolean}

Used to check if adapter is available

Source:
Returns:

true if indexeddb is available, false if not.

Type
boolean

deleteDatabase(dbname, callbackopt)

Deletes a serialized db from the catalog.

Parameters:
Name Type Attributes Description
dbname string

the name of the database to delete from the catalog.

callback function <optional>

(Optional) executed on database delete

Source:
Example
// DELETE DATABASE
// delete 'finance'/'test' value from catalog
idbAdapter.deleteDatabase('test', function {
  // database deleted
});

deleteDatabasePartitions(dbname)

Removes all database partitions and pages with the base filename passed in. This utility method does not (yet) guarantee async deletions will be completed before returning

Parameters:
Name Type Description
dbname string

the base filename which container, partitions, or pages are derived

Source:

getCatalogSummary(callback)

Allows retrieval of list of all keys in catalog along with size

Parameters:
Name Type Description
callback function

(Optional) callback to accept result array.

Source:

getDatabaseList(callback)

Retrieves object array of catalog entries for current app.

Parameters:
Name Type Description
callback function

should accept array of database names in the catalog for current app.

Source:
Example
idbAdapter.getDatabaseList(function(result) {
  // result is array of string names for that appcontext ('finance')
  result.forEach(function(str) {
    console.log(str);
  });
});

loadDatabase(dbname, callback)

Retrieves a serialized db string from the catalog.

Parameters:
Name Type Description
dbname string

the name of the database to retrieve.

callback function

callback should accept string param containing serialized db string.

Source:
Example
// LOAD
var idbAdapter = new LokiIndexedAdapter('finance');
var db = new loki('test', { adapter: idbAdapter });
  db.loadDatabase(function(result) {
  console.log('done');
});

saveDatabase(dbname, dbstring, callback)

Saves a serialized db to the catalog.

Parameters:
Name Type Description
dbname string

the name to give the serialized database within the catalog.

dbstring string

the serialized db string to save.

callback function

(Optional) callback passed obj.success with true or false

Source:
Example
// SAVE : will save App/Key/Val as 'finance'/'test'/{serializedDb}
var idbAdapter = new LokiIndexedAdapter('finance');
var db = new loki('test', { adapter: idbAdapter });
var coll = db.addCollection('testColl');
coll.insert({test: 'val'});
db.saveDatabase();  // could pass callback if needed for async complete