EzDevInfo.com

Dexie.js

Minimalistic IndexedDB API with bullet proof transactions Dexie.js · dfahlander/Dexie.js Wiki · GitHub dexie.js - minimalistic indexeddb api with bullet proof transactions

How to get table after indexedDB was just openned via Dexie.js?

I need to check if some table already exists into IndexedDB just after it was openned. But I don't know how to get DexieDB object inside 'then' statement.

this.db = new Dexie("DBNAME");
if (!this.db.isOpen()) {
    this.db.open().then(function () {
        //how to get this.db.table(storeName) here?
    }).catch(function (error) {
        console.log(error)
    });
}

So this.db doesn't exist inside 'then' statement. How to get it?


Source: (StackOverflow)

Dexie.js not carrying out .add transaction

var db = new Dexie(app.settings.unpublishedBooksDb);
db.version(1).stores({
    friends: "++id,name,shoeSize"
});
db.open();
db.close();

I have a precreated indexedDB database using the code above, and then on another view in the application, I need to add a row to a table.

var db = new Dexie('myDb');
db.open().then(function() {
    console.log ('opened'); //this works
    db.friends.add({name:"Fredrik"}); //this doesnt do anything and adding a catch doesn't throw an error either
}).finally(function () {
    db.close();
});

I tried using .transaction but still the same. If I try using Chrome's console, I get an error : Cannot read property add of undefined


Source: (StackOverflow)

Advertisements