Skip to content

Dexie.IncompatiblePromiseError

David Fahlander edited this page Apr 5, 2016 · 34 revisions

Inheritance Hierarchy

Description

Happens when returning an incompatible Promise from a transaction scope.

Dexie.Promises are compatible with other Promises, but in transaction scopes you must use Dexie.Promise only. Outside transaction scopes, you are free to mix with other promises. The reason is that Dexie's transaction scope needs to do the following:

  • Make sure indexedDB transactions aren't committed too early
  • Keep track of currently ongoing transaction for the particular scope.
  • Detect whether a promise was uncaught and if so, abort the transaction.

Solution:

db.transaction ('rw', db.friends, function() {
    // Always use Dexie.Promise in the scope:
    return Dexie.Promise.all ([  
        db.friends.put({name: "Foo"}),
        db.friends.put({name: "Bar"})
    ]);
});

When using async / await

function putFriends() {
    let Promise = Dexie.Promise; // Make async use Dexie.Promise!
    return db.transaction('rw', db.friends, async () => {
        await db.friends.put({name: "Foo"});
        await db.friends.put({name: "Bar"});
    });
});

...or:

import Dexie from 'dexie';
let Promise = Dexie.Promise;

function putFriends() {
    return db.transaction('rw', db.friends, async () => {
        await db.friends.put({name: "Foo"});
        await db.friends.put({name: "Bar"});
    });
});
Clone this wiki locally