I'm trying to write some code in Angular js, it's my first time so there still are things I don't know. I'm also using PouchDB, and following my logic I'd like to do:
- check is the DB has some stuff in it
- if yes, destroy it, and create a new one
- put new stuff in the DB
It seems pretty straightforward but probably I'm getting lost in the promises...
if (stuffInsideDB != undefined && stuffInsideDB !='')
{
db.destroy().then(
function(result)
{
db = new PouchDB('DB');
db.info();
}
);
}
db.put(
{
_id: (currentIndex + 1).toString(),
"data": encryptedHex.toString()
}
).then(
function()
{ //do something}
);
Executing this code, it's executing the put before the destroy (and of course I'm getting an error). Is it because I'm not doing something like destroy().then(create().then(put())) ?
Many thanks