localForage使用WebSQL web IndexedDB可用

localForage using WebSQL web IndexedDB available

本文关键字:IndexedDB 可用 web WebSQL 使用 localForage      更新时间:2023-09-26

我正在用Ionic框架构建一个Cordova应用程序。我使用angular-localForage作为应用程序持久存储的本地数据库。

在开发时,我正在使用Windows 10上的Google Chrome 45.0.2454.85 m测试我的应用程序。angular-localForage版本为1.2.3,localForage版本为1.2.4。

我可以设置和检索数据没有问题。要设置数据,我使用:

$localForage.setItem(myKey, myData).then(myCallbackFunction);

根据文档,如果IndexedDB可用,localForage应该使用IndexedDB,如果浏览器不可用,则退回到WebSQL。我可以从查看Chrome开发人员工具中的资源中看到,它正在将我的数据存储在WebSQL中。

如果我把这段代码放到控制器中,我得到一条消息,说IndexedDB可用:

if (!window.indexedDB) {
    window.alert("Your browser doesn't support a stable version of IndexedDB. Such and such feature will not be available.");
} else {
    window.alert("IndexedDB available.");
}

我的问题是,当我有IndexedDB可用时,为什么在Chrome中使用WebSQL ?

这个问题其实很狡猾。

TLDR;苹果的UIWebView不支持indexedDB。关闭Chrome的iOS模拟器,看看indexedDB工作

我假设你正在用Chrome开发工具模拟iPhone。嗯,这种欺骗实际上是非常有效的,因为如果您将localForage配置为专门使用indexedDB,那么它现在将发出一个错误。

如果你想有一个深刻的无聊的时刻,看看indexedDB是如何工作的…关闭模拟,这样你就可以使用Chrome自己的用户代理了。那就行了。

来源:我不得不自己处理这些废话。这是一次非常糟糕的开发者体验。哈。

我的猜测是,websql被认为是第一选择,因为它存在的时间比indexeddb api和chrome是推动websql早于indexeddb。由于chrome仍然支持websql,它在indexeddb.