function checkDatabase() {
    let transaction = db.transaction(["BudgetDB"], "readwrite");
    const BudgetStore = transaction.objectStore("BudgetDB");
    var getAll = BudgetStore.getAll();
   

   // If the request was successful
    getAll.onsuccess = function () {
        // If there are items in the store, we need to bulk add them when we are back online
        if (getAll.result.length > 0) {
            fetch('/api/transaction/bulk', {
                method: 'POST',
                body: JSON.stringify(getAll.result),
                headers: {
                    Accept: 'application/json, text/plain, */*',
                    'Content-Type': 'application/json',
                },
            })
            .then((response) => response.json())
            .then((data) => {
                if(data.length > 0) {
                    transaction = db.transaction(["BudgetDB"], "readwrite");
                    const newStore = transaction.objectStore("BudgetDB");
                    // Clear existing entries because our bulk add was successful
                    newStore.clear();
                    console.log('Clearing store 🧹');
                }
            });
        }
    };
}
//Open a transaction on your Budget db
Open a transaction on your Budget db
Open a transaction on your Budget db
function checkDatabase() {
    let transaction = db.transaction(["BudgetDB"], "readwrite");
    const BudgetStore = transaction.objectStore("BudgetDB");
    var getAll = BudgetStore.getAll();
    getAll.onsuccess = function () {
        if (getAll.result.length > 0) {
            fetch('/api/transaction/bulk', {
                method: 'POST',
                body: JSON.stringify(getAll.result),
                headers: {
                    Accept: 'application/json, text/plain, */*',
                    'Content-Type': 'application/json',
                },
            })
            .then((response) => response.json())
            .then((data) => {
                if(data.length > 0) {
                    transaction = db.transaction(["BudgetDB"], "readwrite");
                    const newStore = transaction.objectStore("BudgetDB");
                    newStore.clear();
                    console.log('Clearing store 🧹');
                }
            });
        }
    };
}
function checkDatabase ( ) { let transaction = db . transaction ( [ "BudgetDB" ] , "readwrite" ) ; const BudgetStore = transaction . objectStore ( "BudgetDB" ) ; var getAll = BudgetStore . getAll ( ) ; getAll . onsuccess = function ( ) { if ( getAll . result . length > 0 ) { fetch ( '/api/transaction/bulk' , { method : 'POST' , body : JSON . stringify ( getAll . result ) , headers : { Accept : 'application/json, text/plain, */*' , 'Content-Type' : 'application/json' , } , } ) . then ( ( response ) => response . json ( ) ) . then ( ( data ) => { if ( data . length > 0 ) { transaction = db . transaction ( [ "BudgetDB" ] , "readwrite" ) ; const newStore = transaction . objectStore ( "BudgetDB" ) ; newStore . clear ( ) ; console . log ( 'Clearing store 🧹'); } } ) ; } } ; }
Open a transaction on your Budget db
Open a transaction on your Budget db
// If the request was successful // If there are items in the store, we need to bulk add them when we are back online // Clear existing entries because our bulk add was successful