Javascript 和 Sqlite
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14334292/
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
Javascript and Sqlite
提问by user32262
I am creating an app using HTML5 and Javascript. This app will be compatible with Windows and iOS 6 (iPad). I need a local database access using javascript. This is a pure offline ap with no server side involved.
我正在使用 HTML5 和 Javascript 创建一个应用程序。此应用程序将与 Windows 和 iOS 6 (iPad) 兼容。我需要使用 javascript 访问本地数据库。这是一个纯离线 ap,不涉及服务器端。
My dilemma is -
我的困境是——
WebSQL is not supported anymore by W3C.
IndexedDB works with Firefox but not with iOS6.
Most importantly, I want to avoid HTML5 Local database storage as it cleans data whenever history is cleared.
W3C 不再支持 WebSQL。
IndexedDB 适用于 Firefox,但不适用于 iOS6。
最重要的是,我想避免 HTML5 本地数据库存储,因为它会在清除历史记录时清除数据。
I would like to have a durable database locally for the app, something like SQLite. Is it possible to access SQLite using pure javascript, so that it will work with Firefox on Windows and also on iPad.
我想在本地为应用程序创建一个持久的数据库,例如 SQLite。是否可以使用纯 javascript 访问 SQLite,以便它可以在 Windows 和 iPad 上与 Firefox 一起使用。
EDIT: The app will not be run from the browser in iPad (iOS6). Rather the app will be packaged into ipa file and installed in the iPad device.
编辑:该应用程序不会从 iPad (iOS6) 的浏览器中运行。而是将应用程序打包成 ipa 文件并安装在 iPad 设备中。
采纳答案by Jeffery To
What you're looking for is a polyfill.
您正在寻找的是polyfill。
According to HTML5 Please, IndexedDB Polyfillimplements the IndexedDB APIs over WebSQL. (The author of the polyfill also wrote an articleon Mozilla Hacks about it.)
根据HTML5 Please,IndexedDB Polyfill通过 WebSQL 实现了 IndexedDB API。(polyfill 的作者还写了一篇关于 Mozilla Hacks的文章。)
Facebook also as a polyfill. According to this pull request(to another project), Parashuram Narasimhan, the author of the first polyfill, seems to prefer the Facebook polyfill and is considering retiring his own project. (But then again, the Facebook repo looks like a one-time code dump and may not have any ongoing development.)
Facebook 也作为polyfill。根据这个 pull request(到另一个项目),第一个 polyfill 的作者 Parashuram Narasimhan 似乎更喜欢 Facebook polyfill,并且正在考虑退出他自己的项目。(但话又说回来,Facebook 存储库看起来像是一次性代码转储,可能没有任何正在进行的开发。)
回答by Taha
We had same issue and got answered on this thread.
我们遇到了同样的问题,并在此线程上得到了解答。
Lawnchair is a good choice if you need a single table DB - we had requirement of multiple tables, so have developed own wrapper.
如果您需要单个表 DB,Lawnchair 是一个不错的选择 - 我们需要多个表,因此开发了自己的包装器。
Create a web app using HTML-5 and JavaScript, so that it can work for both desktop browser and iPad. Make it hybrid using PhoneGap for making it iPad's native app.
使用 HTML-5 和 JavaScript 创建一个 Web 应用程序,使其适用于桌面浏览器和 iPad。使用 PhoneGap 使其成为 iPad 的本机应用程序。
回答by Praveen Vijayan
There are some points to note.
有几点需要注意。
- Its a pure client side app.
- Not using webstorage (local and session)
- 它是一个纯粹的客户端应用程序。
- 不使用网络存储(本地和会话)
The options left are using webSQL, IndexedDB, Third-party framework or custom solutions.
剩下的选项是使用 webSQL、IndexedDB、第三方框架或自定义解决方案。
webSQL:- Support is limited to webkit browsers and w3c declared its dead. Browser support
webSQL:- 支持仅限于 webkit 浏览器,w3c 宣布它已死。浏览器支持
IndexedDB:- Supports in IE10, chrome and Firefox. Browser support. Not supported in older versions of IE.
IndexedDB:- 支持 IE10、chrome 和 Firefox。浏览器支持。旧版本的 IE 不支持。
Third-party framework:- sequelsphereis a platform independent solution to address this issue. It is a RDMS written entirly in javascript and make use of webSQL or IndexedDB.
第三方框架:- sequelsphere是一个独立于平台的解决方案来解决这个问题。它是一个完全用 javascript 编写并使用 webSQL 或 IndexedDB 的 RDMS。
custom solutions:- Supporting both IndexedDB and WebSQL on a cross platform web applike this tutorial, we can create our custom cross-browser db solutions or may use lawnchairlike json storage options.
自定义解决方案:-在像本教程这样的跨平台 Web 应用程序上同时支持 IndexedDB 和 WebSQL,我们可以创建我们的自定义跨浏览器数据库解决方案,或者可以使用像 json 存储选项的草椅。
回答by Sanjeeva
Please check whether this might be helpful. you can use javascript for both front-end and back-end (for db interactions). There are so many plugins also available to use for this framwork. http://www.nodejs.org
请检查这是否有帮助。您可以将 javascript 用于前端和后端(用于数据库交互)。有很多插件也可用于此框架。http://www.nodejs.org
回答by Leo Cai
It's 100% possible. I can recommend a javascript lib for data access in html5 sqlite. Documentation & sample code: click here
这是 100% 的可能。我可以推荐一个 javascript 库用于 html5 sqlite 中的数据访问。文档和示例代码:单击此处
I have made a android demo (by using phonegap) with that lib. It works great!
我已经使用该库制作了一个 android 演示(通过使用 phonegap)。效果很好!