Offline access - SQLite or Indexed DB?

后端 未结 8 1297
一生所求
一生所求 2020-12-14 01:39

I am in the R&D phase of developing an application, with the following key requirements:

  • HTML5 web application - which will also have a hybrid version
相关标签:
8条回答
  • 2020-12-14 01:59

    If you don't want to choose between IndexedDB or WebSQL you can use the Javascript library PouchDB.

    I use it in an Android Webview to store offline data and it works pretty well. The data are stored on a local database (using IndexedDB or WebSQL) if there is no internet connection available and is synchronized with a remote database (CouchDB database) when there is an available connection.

    PouchDB will depend on IndexedDB but fall back to WebSQL if IndexedDB is not supported. There is also the possibility to use a SQLite plugin for Cordova/PhoneGap.

    0 讨论(0)
  • 2020-12-14 02:00

    Yes, IndexedDB API is great and all browsers will support in near future.

    I definitely recommend my own solution https://bitbucket.org/ytkyaw/ydn-db it is very thin wrapper for IndexedDB and fall back to Sqlite for safari.

    0 讨论(0)
  • 2020-12-14 02:05

    This may be late to the game, but you could look at: SequelSphere

    It is a 100% HTML5/JavaScript Relational Database that works cross-browser and uses local storage to persist it's data. You can use SQL to query it as well. It is it's own database engine, and doesn't rely upon the built-in (WebSQL) relational databases. As such, it will work across all browsers.

    While it currently only supports localStorage, the idea is to support all the standards going forward. As browsers support other types of persistence, SequelSphere would take advantage of that. The positive is that you only code against SequelSphere using standard SQL, and let it handle the persistence.

    Nevertheless, be aware that it is a new product to the market, so that comes with both positives and negatives.

    0 讨论(0)
  • 2020-12-14 02:08

    I think abandoning IndexedDB would be a bad idea, because it's probably the format of the future, so Safari might stop supporting WebSQL.

    It appears there are various JavaScript solutions to bridge the gap between the two - saving in whichever is available on the user's browser: JavaScript Library to Bridge IndexedDB and WebSQL I think this is probably your best solution.

    0 讨论(0)
  • 2020-12-14 02:08

    IndexedDB is most likely the supported database of the future and it would be best to go with that instead of WebSQL. As Raymond pointed, it is best to refer to http://www.caniuse.com to see the current/future support in both desktop and mobile browsers.

    Depending on the current needs of your solution, you might be fine with one of the many JavaScript libraries that are available which use the local storage and provide a query interface. One of the libraries, which has worked well for me is Lawnchair.

    0 讨论(0)
  • 2020-12-14 02:09

    First of all, the one that has been deprecated by W3C is WebSQL not SQLite

    IndexedDB -

    • It is incompatible with many types of mobile OS and is only compatible with certain types of versions of mobile OS
    • Developers cannot use SQL with IndexedDB. They can with SQLite and WebSQL
    • Most developers actively avoid using IndexedDB as much as they can

    WebSQL -

    • It has been deprecated by W3C which means it is no longer maintained or developed
    • It requires another plugin called Polyfill to enable mobile applications to work with popular mobile OS such as Google Android and Apple iOS

    SQLite -

    • It received an award from Google
    • SQLite has its official website. IndexedDB and WebSQL do not
    • On Google, SQLite returns 4.3 million results. WebSQL returns a bit less than 700K results and IndexedDB returns 282K results.

    If you want a quick tutorial on SQLite,

    Storage of SQLite database using Android and Phonegap

    0 讨论(0)
提交回复
热议问题