Syntax

db.use({stack, name?, create})

Properties of the parameter

stack : String Stack type. Currently, only "dbcore" is supported.
name : String Optional name of your middleware
create : Function The middleware itself. It takes a DBCore instance and should return a modified DBCore instance.

Remarks

Your provided create function takes a DBCore and should return another plain JS object confirming to the DBCore interface.

Example

import Dexie from 'dexie';

const db = new Dexie('dbname');

db.use({
  stack: "dbcore", // The only stack supported so far.
  name: "MyMiddleware", // Optional name of your middleware
  create (downlevelDatabase) {
    // Return your own implementation of DBCore:
    return {
      // Copy default implementation.
      ...downlevelDatabase, 
      // Override table method
      table (tableName) {
        // Call default table method
        const downlevelTable = downlevelDatabase.table(tableName);
        // Derive your own table from it:
        return {
          // Copy default table implementation:
          ...downlevelTable,
          // Override the mutate method:
          mutate: req => {
            // Copy the request object
            const myRequest = {...req};
            // Do things before mutate, then
            // call downlevel mutate:
            return downlevelTable.mutate(myRequest).then(res => {
              // Do things after mutate
              const myResponse = {...res};
              // Then return your response:
              return myResponse;
            });
          }
        }
      }
    };
  }
});

In essence, all mutating operations are bulk-oriented. There’s only bulkPut(), bulkAdd(), bulkDelete() and deleteRange(). Currently all of these four are reached through a single method mutate().

Interface definitions for DBCore is found here

Table of Contents