Skip to content

Commit

Permalink
Delete DB schemes on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub Šlambora committed Nov 28, 2020
1 parent f130e21 commit acbae39
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ export const indexScheme = "index";
* @returns {Promise<IDBDatabase>}
*/
export async function openDb() {
const request = indexedDB.open(booksDatabase, 2);

request.onupgradeneeded = (event) => {
//TODO clear DB
const request = indexedDB.open(booksDatabase, 3);

request.onupgradeneeded = event => {
const db = event.target.result;

db.deleteObjectStore(booksScheme);
db.deleteObjectStore(pagesScheme);
db.deleteObjectStore(indexScheme);

const bookStore = db.createObjectStore(booksScheme, {
keyPath: "id",
autoIncrement: true,
Expand All @@ -41,8 +43,8 @@ export async function openDb() {
};

return new Promise((resolve, reject) => {
request.onsuccess = (event) => resolve(event.target.result);
request.onerror = (event) => {
request.onsuccess = event => resolve(event.target.result);
request.onerror = event => {
console.log(`uuGle: error opening database ${booksDatabase}`);
reject();
};
Expand All @@ -56,8 +58,8 @@ export async function openDb() {
*/
export async function requestToPromise(request) {
return new Promise((resolve, reject) => {
request.onsuccess = (event) => resolve(event.target.result);
request.onerror = (event) => reject(event.target.error);
request.onsuccess = event => resolve(event.target.result);
request.onerror = event => reject(event.target.error);
});
}

Expand Down

0 comments on commit acbae39

Please sign in to comment.