SQLite vs LocalStorage

2019-06-14 04:13发布

问题:

I am using Ionic 2.

I have a simple Chat App which uses Meteor to sync the messages between users. At this stage, all messages are stored on the server in a Mongodb database. It works perfectly.

I do however, want to store the messages on the uses local device rather, once downloaded from the server, much like WhatsApp does.

Question

Should I user Local Storage or SQLite?

I am leaning towards Local Storage because the object I save are pretty simple (just a key and a string).

Local Storage I plan to save the messages in simple JSON with a key.

SQLite I have never used this before, but understand normal SQL.

回答1:

Since your data will be simple objects , it is recommended you go for NoSQL DB instead of SQLite

In NoSQL Database you can store your app data in files.You will have the liberty to store your objects as per your structure, as in your case - key value pairs. Even after uninstalling the app, the app data will be persistent as you can store the data in external storage of the device

I would recommend please go through

http://developer.couchbase.com/documentation/mobile/1.1.0/develop/training/build-first-android-app/index.html

Its a very good library for android NoSQL DB.



回答2:

The local storage store the data locally within the user's browser. And is very helpful for store small pieces of data. But remember, the browser has a limit to store data with local storage and depends which browser that you using.

Look at this link to might help you about the limits.

So, for your application the sqlite or nosql seems more suitable for your needs.