javascript - 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 precreated indexeddb database using code above, , on view in application, need add row table.

var db = new dexie('mydb'); db.open().then(function() {     console.log ('opened'); //this works     db.friends.add({name:"fredrik"}); //this doesnt , adding catch doesn't throw error either }).finally(function () {     db.close(); }); 

i tried using .transaction still same. if try using chrome's console, error : cannot read property add of undefined

your second db instance contains no info tables contain. implicit table property (db.friends) not there. happens throws typeerror: cannot read property 'add' of undefined. if catch call (not finally), typeerror catched.

what can reference friends table db.table('friends').add ({name: 'fredrik'}) instead of db.friends.add({name: 'fredrik'}).

beware though defining database without specifying table schema not thorowgly tested , used, recommend using schema defined avoid other pitfalls well. if architectural reasons still need way, aware transaction scopes works little different since cannot use dynamic implicit tale properties in transaction scopes either , db.table() not return transaction-bound table instance if in transaction scope. have use old transaction api:

db.transaction('rw', 'friends', function (friends, trans) {     friends.put({name: 'fredrik'}); }); 

...instead of:

db.transaction('rw', 'friends', function () {     db.friends.put({name: 'fredrik'}); }); 

best wishes, david


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -