Loki/Sylvie encrypted persistence adapter class for indexedDb. This class fulfills abstract adapter interface which can be applied to other storage methods. Utilizes the included SylvieCatalog app/key/value database for actual database persistence. IndexedDb storage is provided per-domain, so we implement app/key/value database to allow separate contexts for separate apps within a domain.

Example

var idbAdapter = new IndexedDBAdapter('finance');

Hierarchy

  • IndexedDBAdapter

Implements

Constructors

Properties

app: string
catalog: IDBCatalog
isAsync: true
mode: "normal"
options: Partial<IndexedDBAdapterOptions>

Methods

  • Deletes a serialized db from the catalog.

    Example

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

    Memberof

    SylvieIndexedAdapter

    Parameters

    • dbname: string

      the name of the database to delete from the catalog.

    • Optional callback: ((_: Error | {
          success: true;
      } | {
          error: Error;
          success: false;
      }) => any)

      (Optional) executed on database delete

        • (_: Error | {
              success: true;
          } | {
              error: Error;
              success: false;
          }): any
        • Parameters

          • _: Error | {
                success: true;
            } | {
                error: Error;
                success: false;
            }

          Returns any

    Returns void

  • 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

    Memberof

    SylvieIndexedAdapter

    Parameters

    • dbname: any

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

    Returns void

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

    Memberof

    LokiIndexedAdapter

    Parameters

    • callback: any

      (Optional) callback to accept result array.

    Returns void

  • Retrieves object array of catalog entries for current app.

    Example

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

    Memberof

    SylvieIndexedAdapter

    Parameters

    • callback: ((_: string[] | Error) => void)

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

        • (_: string[] | Error): void
        • Parameters

          • _: string[] | Error

          Returns void

    Returns void

  • Retrieves a serialized db string from the catalog.

    Example

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

    Parameters

    • dbname: string

      the name of the database to retrieve.

    • callback: ((serialized: string) => void)

      callback should accept string param containing serialized db string.

        • (serialized: string): void
        • Parameters

          • serialized: string

          Returns void

    Returns void

  • Retrieves a serialized db string from the catalog, returns a promise to a string of the serialized database.

    Returns

    A promise to a string of the serialized database.

    Example

    const db = new Sylvie(TEST_DB_NAME, {
    adapter: new IndexedDBAdapter();
    });
    await db.loadDatabaseAsync({});
    // db is now ready to use
    // you can also chain the promises
    await db.loadDatabaseAsync({}).then(() => {
    // db is now ready to use
    });
    // or use async await syntax
    await db.loadDatabaseAsync({});
    // db is now ready to use

    Memberof

    IndexedDBAdapter

    Throws

    If the database is not found.

    Throws

    If the database is not decrypted successfully.

    Throws

    If the database is not deserialized successfully.

    Parameters

    • dbname: string

    Returns Promise<string>

  • Saves a serialized db to the catalog.

    Example

    // SAVE : will save App/Key/Val as 'finance'/'test'/{serializedDb}
    var idbAdapter = new SylvieIndexedAdapter('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

    Parameters

    • dbname: string

      the name to give the serialized database within the catalog.

    • dbstring: string

      the serialized db string to save.

    • Optional callback: ((err: Error | {
          success: true;
      } | {
          error: Error;
          success: false;
      }) => void)

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

        • (err: Error | {
              success: true;
          } | {
              error: Error;
              success: false;
          }): void
        • Parameters

          • err: Error | {
                success: true;
            } | {
                error: Error;
                success: false;
            }

          Returns void

    Returns void

Generated using TypeDoc