Minimalistic IndexedDB API with bullet proof transactions
Dexie.js · dfahlander/Dexie.js Wiki · GitHub dexie.js - minimalistic indexeddb api with bullet proof transactions
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)
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)