Indexeddb: Differences between onsuccess and oncomplete?

I use two different events to respond to a response when an IndexedDB transaction completes or completes:

Let's say ... db: IDBDatabase object, tr: IDBTransaction object, os: IDBObjectStore object

tr = db.transaction(os_name,'readwrite');
os = tr.objectStore();

case 1:

r = os.openCursor();
r.onsuccess = function(){
    if(r.result){
        callback_for_result_fetched();
        r.result.continue;
    }else callback_for_transaction_finish();
}

case 2:

tr.oncomplete = callback_for_transaction_finish();

It is a waste if both of them work the same. Can you tell me if there is a difference between the two?

+5
source share
3 answers

While this is true, these callbacks work the same, they do not match: the difference between onsuccessand oncompleteis that the transactions complete, but the requests made on these transactions, make up successful.

oncomplete . onsuccess.

+8

, , - ...

, .

, Store . . , () DB:

var trx = dbInstance.transaction([storeIdA, storeIdB], 'readwrite'),
    storeA = trx.objectStore(storeIdA),
    storeB = trx.objectStore(storeIdB);

    trx.oncomplete = function(event) {
        // this code will run only when ALL of the following requests are succeed
        // and only AFTER ALL of them were processed
    };
    trx.onerror = function(error) {
        // this code will run if ANY of the following requests will fail
        // and only AFTER ALL of them were processed
    };

    storeA.put({ key:keyA, value:valueA });
    storeA.put({ key:keyB, value:valueB });
    storeB.put({ key:keyA, value:valueA });
    storeB.put({ key:keyB, value:valueB });

W3C spec:

, , complete event, , - .

+8

, garentee, trx.oncomplete , / :

trx.oncomplete, db . FireFox , , : https://developer.mozilla.org/en-US/docs/Web/API/IDBTransaction/oncomplete

It seems that windows / edge also has the same problem. In principle, there is no guarantee that your application will have data written to the database if / when the user decides to kill or disconnect the device. We even tried to wait up to 15 minutes before closing in some cases and did not see the recorded data. For me, I would always like to make sure that the data record is complete and committed.

Are there other solutions for a real permanent database or improvements for IndexedDB beyond the experimental FF addition ...

+2
source

All Articles