When deleting an entry from an IndexedDB wrapped by Dexie the promise success handler shows the number of deleted records (which is one in my case), but looking into the database in Chrome or Safari after the operation is completed the entry still exists there.
The table has a primary key consisting of three string setup as a compound key.
I have tried some to change my query to delete the entry in different ways. But in the end all of them resulted in pretending to have one entry deleted but in fact it wasnt.
Setup of database:
constructor() {
super('ConfirmationDatabase');
this.version(ConfirmationDatabaseService.VERSION_ONE).stores({
confirmations: '[frontid+qmnum+manum]',
});
}
Version 1 of code to delete an entry:
return new Promise((resolve, reject) => {
this.confirmations
.where({
frontid: id.getFrontId(),
qmnum: id.getQmnum(),
manum: id.getManum(),
})
.delete()
.then((result: any) => { // <--- result equals 1
this.confirmations
.where({
frontid: id.getFrontId(),
qmnum: id.getQmnum(),
manum: id.getManum(),
})
.first()
.then((conf) => {
console.log(conf); // this is undefined
});
resolve(true);
})
.catch((error) => reject(error));
});
After the deletion operation I am immediately reading the value again for testing purpose. It wont find it, but when the function has ended, the entry is still in the database.
Tried this code also: Version 2 of code to delete an entry:
return new Promise((resolve, reject) => {
this.confirmations
.where('[frontid+qmnum+manum]')
.equals([id.getFrontId(), id.getQmnum(), id.getManum()])
.delete()
.then((result: number) => {
if (result === 1) {
resolve(true); // <--- this is reached
} else {
reject(`Confirmation with following key could not be deleted from database: ${id.toString()}`);
}
resolve(true);
})
.catch((error) => {
reject(
`Confirmation with following key could not be deleted from database: ${id.toString()}. Error ${JSON.stringify(
error
)}`
);
});
});
I dont get any error message nor is the promise rejected. It pretends it did it, but in Chrome or Safari developer tools its still visible. Even if I read the entry from the object by code later on its again still returned. I am wondering if I need to commit a transaction somehow? Can it have to do that I mixing ExtendedPromise (Dexie) with ES6 Promises? But if so, I found the example on the Dexie documentation.
Any help appreciated what I am doing wrong.
In theory, if you'd execute this code within a transaction and your code throws an error directly after your promise resolves, that traction would be rolled back.
But I would rather suspect that something in your code is putting the object back again.
Try what happens if you subscribe to the Table.hooks to log creates and deletions. Is the object created again after your deletion?