I'm using this library to run IndexedDB functions more easily:
Dexie
But the code does not follow the order of execution in any way and this causes my script to not work.
Example
This code is just an example to show that it does not follow the order of execution, where you can observe the browser console while refreshing the page:
View in JSFiddle .
var db = new Dexie('teste');
var atual_sequence = 0;
db.version(1).stores({sequences: '++id,of'});
db.open().catch(function(error){
});
db.sequences.where("of").equalsIgnoreCase('0').count(function (count) {
atual_sequence = count;
console.warn(atual_sequence);
});
db.sequences.add({of: '0'});
console.log('ds: '+atual_sequence);
It runs console.log('ds: '+atual_sequence);
before getting the sequence number, is there any way to fix this?