i'm just starting out with Dexie, and I seem to be coming unstuck.
I have a small database (less than 1000 rows), and i'm trying to delete each row one-by-one once I know that the row has been sent to a remote API. I can also successfully save to the table (which is defined by an ID and a column storing a serialised object)
here's my code:
if (online) {
    //we query the db and send each event
    database.open()
    let allEvents = database.events.toCollection()
    let total = allEvents.count(function (count) {
        console.log(count + ' events in total')
        //a simple test to ensure we're seeing the right number of records
    })
    allEvents.each(function(thisEvent){
        //push to remote API
        console.log('deleting ' + thisEvent.id)
        database.events.delete(thisEvent.id) //<= this doesn't seem to be working
    })
}
All of this with the exception of the final delete statement. Any ideas on how I should fix this? the important thing for me is to delete on a per-row basis.
thanks in advance!
I was experiencing the same problem, and the answer from Eugenia Pais wasn't working for me. So after some tests, I saw the trouble was with the type of the variable: I was using a string, but a number is needed, so this is how I solved it:
function removeRow (primaryKey) {
  primaryKey = parseInt(primaryKey);
  databaseName.tableName.where('primaryKey').equals(primaryKey).delete().then(function(deleteCount) {
    console.log ("Deleted " + deleteCount + " rows");
  }).catch(function(error) {
    console.error ("Error: " + error);
});
So be aware you are using a number as argument.
The correct way to delete each row should be selecting the specific row and delete it:
database.tableName.where(indexId).equals(indexValue).delete(); answered Nov 18 '22  17:11
                                    
                            answered Nov 18 '22  17:11
                                                                            If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With