An improved Loki persistence adapter for IndexedDB (not compatible with LokiIndexedAdapter) Unlike LokiIndexedAdapter, the database is saved not as one big JSON blob, but split into small chunks with individual collection documents. When saving, only the chunks with changed documents (and database metadata) is saved to IndexedDB. This speeds up small incremental saves by an order of magnitude on large (tens of thousands of records) databases. It also avoids Safari 13 bug that would cause the database to balloon in size to gigabytes

The `appname` argument is not provided - to distinguish between multiple app on the same
domain, simply use a different Loki database name

Example

var adapter = new IncrementalIndexedDBAdapter();

Param

Configuration options for the adapter

Param

Function to call on IDBDatabase.onversionchange event (most likely database deleted from another browser tab)

Param

Function to call once IDB load has begun. Use this as an opportunity to execute code concurrently while IDB does work on a separate thread

Param

Called when this adapter is forced to overwrite contents of IndexedDB. This happens if there's another open tab of the same app that's making changes. You might use it as an opportunity to alert user to the potential loss of data

Param

Called with a chunk (array of Loki documents) before it's saved to IndexedDB. You can use it to manually compress on-disk representation for faster database loads. Hint: Hand-written conversion of objects to arrays is very profitable for performance. If you use this, you must also pass options.deserializeChunk.

Param

Called with a chunk serialized with options.serializeChunk Expects an array of Loki documents as the return value

Param

Number of parallel requests for data when loading database. Can be tuned for a specific application

Param

Names of collections that should be deserialized lazily Only use this for collections that aren't used at launch

Hierarchy

  • IncrementalIndexedDBAdapter

Implements

Constructors

  • Parameters

    • Optional options: {
          deserializeChunk?: ((collectionName: string, chunk: string) => any[]);
          lazyCollections?: string[];
          megachunkCount?: number;
          onDidOverwrite?: (() => void);
          onFetchStart?: (() => void);
          onversionchange?: ((versionChangeEvent: IDBVersionChangeEvent) => void);
          serializeChunk?: ((collectionName: string, chunk: any[]) => string);
      }
      • Optional deserializeChunk?: ((collectionName: string, chunk: string) => any[])
          • (collectionName: string, chunk: string): any[]
          • Parameters

            • collectionName: string
            • chunk: string

            Returns any[]

      • Optional lazyCollections?: string[]
      • Optional megachunkCount?: number
      • Optional onDidOverwrite?: (() => void)
          • (): void
          • Returns void

      • Optional onFetchStart?: (() => void)
          • (): void
          • Returns void

      • Optional onversionchange?: ((versionChangeEvent: IDBVersionChangeEvent) => void)
          • (versionChangeEvent: IDBVersionChangeEvent): void
          • Parameters

            • versionChangeEvent: IDBVersionChangeEvent

            Returns void

      • Optional serializeChunk?: ((collectionName: string, chunk: any[]) => string)
          • (collectionName: string, chunk: any[]): string
          • Parameters

            • collectionName: string
            • chunk: any[]

            Returns string

    Returns IncrementalIndexedDBAdapter

Properties

mode: "incremental"

Methods

  • Parameters

    • idbStore: any
    • loki: any
    • incremental: any
    • maxChunkIds: any

    Returns {
        collectionVersionIds: any[];
        lokiVersionId: any;
    }

    • collectionVersionIds: any[]
    • lokiVersionId: any
  • Deletes a database from IndexedDB

    Example

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

    Memberof

    IncrementalIndexedDBAdapter

    Parameters

    • dbname: any

      the name of the database to delete from IDB

    • callback: any

      (Optional) executed on database delete

    Returns void

  • Retrieves a serialized db string from the catalog.

    Example

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

    Memberof

    IncrementalIndexedDBAdapter

    Parameters

    • dbname: any

      the name of the database to retrieve.

    • callback: any

      callback should accept string param containing serialized db string.

    Returns void

  • Incrementally saves the database to IndexedDB

    Example

    var idbAdapter = new IncrementalIndexedDBAdapter();
    var db = new loki('test', { adapter: idbAdapter });
    var coll = db.addCollection('testColl');
    coll.insert({test: 'val'});
    db.saveDatabase();

    Memberof

    IncrementalIndexedDBAdapter

    Parameters

    • dbname: any

      the name to give the serialized database

    • getLokiCopy: any

      returns copy of the Loki database

    • callback: any

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

    Returns void

Generated using TypeDoc