最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to read current db version number in dexie? - Stack Overflow

programmeradmin7浏览0评论

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:

db.version(1).stores(/* my schema */) // remove this code
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:

db.version(1).stores(/* my schema */) // remove this code
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 badges
Add a ment  | 

2 Answers 2

Reset to default 5

It 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 the IndexedDB. It's the Dexie.verno multipled by 10. 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
});
发布评论

评论列表(0)

  1. 暂无评论