In Dexie, when you need to upgrade your schemas or table architectures, you use db.version(X)
method.
The library will then check whether the user's browser has a previous version cached and do the appropriate upgrade steps.
But I cannot find how to read the current user's db version manually.
So for example if write this purposefully breaking code:
// remove this code db.version(1).stores(/* my schema */)
db.version(2).stores(/* my schema */)
The library will politely throw an error saying that the version the user currently has (obviously, 1
) has no schema.
But is there a way to read what version exactly the user has?
It could be useful for debugging!
In Dexie, when you need to upgrade your schemas or table architectures, you use db.version(X)
method.
The library will then check whether the user's browser has a previous version cached and do the appropriate upgrade steps.
But I cannot find how to read the current user's db version manually.
So for example if write this purposefully breaking code:
// remove this code db.version(1).stores(/* my schema */)
db.version(2).stores(/* my schema */)
The library will politely throw an error saying that the version the user currently has (obviously, 1
) has no schema.
But is there a way to read what version exactly the user has?
It could be useful for debugging!
Share Improve this question edited Feb 12, 2021 at 15:28 NearHuscarl 82.1k23 gold badges320 silver badges282 bronze badges asked May 19, 2017 at 14:11 timetowondertimetowonder 5,4717 gold badges37 silver badges54 bronze badges2 Answers
Reset to default 5It is possible to skip the whole version()
thing if you only want to inspect the database. For instance, I'm able to print the version number of my database by using this code.
new Dexie("myDB").open().then((db) => console.log(db.verno))
Note that (as stated in the documentation), Dexie multiples the version number set through .version()
by 10 so if you inspect the database in your browser's debugger you will see a number which is 10 times the number you get from using the verno
field.
In Dexie version 3+. You can use:
Dexie.verno
: to get the dexie version. The dexie version is the highest value of the registered versions.Dexie.idbdb.version
: to get the native version of theIndexedDB
. It's theDexie.verno
multipled by10
. See here for more technical explanation.
const db = new Dexie("AppDB");
db.version(1);
db.version(2);
db.version(5);
db.open();
db.on("ready", () => {
console.log(db.verno); // 5
console.log(db.idbdb.version); // 50
});