javascript 用于cordova应用程序的本地存储与数据库(SQLite)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31902562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
local storage vs database(SQLite) for a cordova app
提问by Ankur Bhatia
I am developing a mobile app using javascript and cordova framework. My requirement is that a user enters something in the input textbox. This needs to be stored so that the user need not enter the same text again. It should be already present as a list or something. I went though a lot of documentation. Could someone tell me what is the difference in the local storage (HTML5 storage Apis) and SQL Lite database. And which one should I use for this use case?
我正在使用 javascript 和cordova 框架开发移动应用程序。我的要求是用户在输入文本框中输入一些内容。这需要存储,以便用户无需再次输入相同的文本。它应该已经作为列表或其他东西存在。我去了很多文档。有人能告诉我本地存储(HTML5 存储 API)和 SQL Lite 数据库有什么区别。我应该在这个用例中使用哪个?
Thanks
谢谢
回答by brodybits
Local storage using the HTML5 storage APIs stores your data in its own directory. It will not be backed up reliably, if at all. It is also subject to the limits imposed by the browser.
使用 HTML5 存储 API 的本地存储将您的数据存储在其自己的目录中。它不会得到可靠的备份,如果有的话。它也受到浏览器施加的限制。
A sqlite database, if created using https://github.com/litehelpers/Cordova-sqlite-storage, is stored in a location that is known and will be backed up. (It is possible to store the sqlite database in a location that is NOT backed up by iCloud.) This plugin provides the same Javascript API for iOS, Android, Windows Phone 8, and Windows "Universal" (Windows 8, Windows 8.1, and Windows Phone 8.1).
sqlite 数据库(如果使用https://github.com/litehelpers/Cordova-sqlite-storage创建)存储在已知位置并将进行备份。(可以将 sqlite 数据库存储在未由 iCloud 备份的位置。)此插件为 iOS、Android、Windows Phone 8 和 Windows“通用”(Windows 8、Windows 8.1 和Windows 电话 8.1)。
DISCLAIMER May 2016:I am the primary owner and maintainer of Cordova-sqlite-storage.
免责声明 2016 年 5 月:我是 Cordova-sqlite-storage 的主要所有者和维护者。
回答by Matías Fidemraizer
Local storage is a DOM-standard key-value permanent storage until the user throws away the history, and it has a size limit from 5 to 10MB. Since you're using Cordova, there's no history to throw away, but if the app were hosted as standard Web browser app, the history comes to play as I mentioned above.
本地存储是 DOM 标准的键值永久存储,直到用户丢弃历史记录,并且它的大小限制为 5 到 10MB。由于您使用的是Cordova,因此没有可丢弃的历史记录,但如果该应用程序作为标准 Web 浏览器应用程序托管,那么历史记录将如我上面提到的那样播放。
A SQLite database is a full regular relational embedded storage and it can be a good friend if you want to cache/store large amounts of data on the client-side and you need to query it by complex criterias.
SQLite 数据库是一个完整的常规关系嵌入式存储,如果您想在客户端缓存/存储大量数据并且需要通过复杂的条件查询它,它可能是一个好朋友。