Skip to content

Commit

Permalink
Change IDB to version 3 to force newer structure
Browse files Browse the repository at this point in the history
  • Loading branch information
DAG100 committed Mar 14, 2024
1 parent 061dd91 commit 3a8eea6
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions components/data_worker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async function start_IDB() { //if this resolves, the global variable 'db' should
return new Promise((resolve, reject) => {
db = "";
try {
const openRequest = indexedDB.open("students", 2);
const openRequest = indexedDB.open("students", 3);
openRequest.addEventListener("error", (error) => {
// console.error("Failed to access local database.");
// console.log(error);
Expand All @@ -123,9 +123,17 @@ async function start_IDB() { //if this resolves, the global variable 'db' should
resolve("Success");
}, {once: true});
openRequest.addEventListener("upgradeneeded", (event) => {
db = event.target?.result;
//delete the previous db because I am a bad programmer and I am using upgradeneeded to fix issues
//try/catch so that if it isn't there, it doesn't stop the whole thing
try {
db.deleteObjectStore("students");
console.log("Deleted old table");
} catch (err) {
console.error("Error in deleting students db on version change", err);
}
//set up the DB, and if nothing goes wrong (i.e. no errors) then resolve successfully
// console.log("Setting up IDB");
db = event.target?.result;
const objStore = db.createObjectStore("students", {keyPath:"key", autoIncrement: false});
objStore.createIndex("students", "students", {unique: false}) //this will hold the array/json string of the response
// console.log("Finished setting up IDB");
Expand Down

0 comments on commit 3a8eea6

Please sign in to comment.