IndexedDB - ObjectStores vs multiple databases vs indices?

☆樱花仙子☆ 提交于 2021-02-07 05:29:05

问题


I was wondering when it would be a good idea to have a single database vs one database with multiple object stores. I've read most tutorials on the web as well as looked at the specification for indexedDB, but could not find a good example comparing these different concepts. Does anyone have a concrete example (a design model using multiple object stores and/or code) for this sort of thing?


回答1:


As long as there is no cross transactional manipulation among object stores, you can separate them into multiple databases. I prefer to use separate database, as many as possible, so that schema changes are easier in smaller object store database.

In rare situation, I even use separate database even if cross transaction is require. These cases are found between user setting database and application database. Inconsistency between user setting and application are fine, since the truth is in user setting and temporary inconsistency does not matter.

Notice that there is high cost associate with opening a database. But once it is open, there is no memory consume for the connection. There is no limit in number of databases.

Multiple databases will have higher thourghput than single database with multiple object stores, since implementation of Firefox lock down whole database on any write transaction.



来源:https://stackoverflow.com/questions/28031931/indexeddb-objectstores-vs-multiple-databases-vs-indices

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!