从 javascript 获取 HTML5 WebDB (Web SQL) 数据库的大小
我正在使用 HTML5 中的 WebDB 规范来创建用于持久脱机存储的脱机数据库。但是,我需要一种方法来从 javascript 获取数据库的当前大小。
我唯一能想到的就是循环遍历数据库中的所有内容,并添加所有对象的大小。唯一的问题是这仅适用于原始值,因此只有当我首先序列化所有 javascript 对象(使用 JSON)时这才有效,并且看起来像是一个 hack。
有更好的方法吗?我需要准确的数字。
感谢您的帮助
I'm using the WebDB spec in HTML5 to create an offline database for persistent offline storage. However, I need a way to get the current size of the database from javascript.
The only thing I can think of is to loop through everything in the database, and add the size of all the objects. The only problem is this only works for primitive values, so this would only work if I first serialized all of my javascript objects (using JSON), and seems like a hack.
Is there any better way of doing it? I need accurate numbers.
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

痛苦的解决方案,但我正在做的是在本地存储中为数据库中的每个表使用一个大小计数器,并包装插入、选择、更新、删除等。我不认为这会解释 sqlite 历史记录,但它应该提供一些根据需要限制增长或删除旧数据的方法。
Painful solution but what I'm doing is using a size counter in local storage for each table in the DB and wrapping insert, select, update, drop etc. I don't think this will account for sqlite history, but it should provide some way to constrain growth or drop older data as needed.