Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Indexed db loop through table data and send it to server

97 views
Skip to first unread message

Dorababu Meka

unread,
Nov 18, 2021, 4:02:27 PM11/18/21
to Chromium HTML5
Hi all I have few tables where I am syncing data to server on a timely basis. I have 3 tables where the data has a relation to other table. I know the db is not relational but this is how I created

TableA 
    TableAId  Column1 Column2 
           1                xyz          ABC 
            2               PQR         TCG

TableB 
    TableBId TableAId Column1 Column2 
           1             1              xyz           ABC 
            2            2              PQR          TCG

TableC 
      TableCId TableBId Column1 Column2 
             1                1               xyz       ABC 
              2               1               PQR       TCG 

I have written some code to get all the data and send it to server one by one, the code is working when I have single row in each table. When I had the multiple rows the data is getting duplicated

This is the common method I wrote to get all the data

function getIndexeDbData(storeName, callback) {
        var myDB = window.indexedDB.open(dbName); 
         myDB.onsuccess = function () { 
          try { 
              if (this.result.objectStoreNames.contains(storeName)) {                       
               this.result.transaction(storeName).objectStore(storeName).getAll().onsuccess = function (event) { callback(event.target.result); }; } else { callback(false); } } catch (ex) { } }; }

This is how calling FormData syncFormData =new FormData();
  
unction SyncData() { getIndexeDbData("TableA", function (data) { $.each(data, function (i, tblAData) { FormData syncFormData = new FormData(); syncFormData.append('TableA.Column1', tblAData.Column1); syncFormData.append('TableA.Column2', tblAData.Column2); getTable2(tblAData.TableAId) }); }); } function getTable2(id) { getIndexeDbData("TableB", function (data) { var tblbData= data.filter(x => x.TableAId === id); syncFormData.append('TableB.Column1', tblbData.Column1); syncFormData.append('TableB.Column2', tblbData.Column2); getTable3(tblbData.TableBId); }); } function getTable3(id) { getIndexeDbData("TableC", function (data) { var tblCData= data.filter(x => x.TableBId === id); postToDb() // Where I am calling ajax to post to server }); }
 
Reply all
Reply to author
Forward
0 new messages