From c13f21d65edde94d7fa7d6fb788435bfe7d6062e Mon Sep 17 00:00:00 2001 From: xehpuk Date: Mon, 15 Jun 2020 17:24:39 +0200 Subject: [PATCH] Fixed onupgradeneeded handling `openRequest.result.version` in `onupgradeneeded` is not the current DB version. It is the requested version, equal to `event.newVersion`. `event.oldVersion` contains the current version. --- 6-data-storage/03-indexeddb/article.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/6-data-storage/03-indexeddb/article.md b/6-data-storage/03-indexeddb/article.md index 7b93fd12..3f0cf0e5 100644 --- a/6-data-storage/03-indexeddb/article.md +++ b/6-data-storage/03-indexeddb/article.md @@ -5,7 +5,7 @@ libs: # IndexedDB -IndexedDB is a database, that is built into browser, much more powerful than `localStorage`. +IndexedDB is a database that is built into browser, much more powerful than `localStorage`. - Stores almost any kind of values by keys, multiple key types. - Supports transactions for reliability. @@ -75,10 +75,10 @@ We can open it with version `2` and perform the upgrade like this: ```js let openRequest = indexedDB.open("store", *!*2*/!*); -openRequest.onupgradeneeded = function() { +openRequest.onupgradeneeded = function(event) { // the existing database version is less than 2 (or it doesn't exist) let db = openRequest.result; - switch(db.version) { // existing db version + switch(event.oldVersion) { // existing db version case 0: // version 0 means that the client had no database // perform initialization