What persistent data storages should i use?

with pouchdb you can sync user data with couchdb and I think that it resolves problem with reinstall / upgrade.

it’s very useful if user have more devices, because he can use same data on all of them.

@kevbaker: I’m testing now GQL and we’ll see, but pouchdb without GQL is still the best choice for me.

I’m bumping the thread to share my experience:

I’ve settled with localForage as it has a very good abstraction layer through localStorage-like setters and getters and it does solve the 5MB limit when other storage methods are available (it tries IndexedDB and WebSQL first, so it solves the 5MB limit almost everywhere these days).

It’s very simple to use and it’s “own” choice of drivers seems consistent as I’ve tried in different environments and it always chooses the same driver for each different environment and apparently always the most logical choice.

I’m just leaving my opinion in case anyone is still undecided. :slight_smile:

There are some good suggestions here. I use persistencejs. It has a nice ORM with support for relational data.

I have used it several times in the past (with a modified version of the ‘sync’ portion) to sync data between multiple devices and a web application. It is also really lightweight for the featureset.

If anyone is interested in helping refactor it into angularjs modules, let me know. I am planning to open-source a new version of the sync module with better support for $http and promises.

2 Likes

Thanks … All suggestions in this posts are helpful and by it seems that sqlite is the best option. I only have one doubt regarding SQL. If I use the SQL database the same way I use localstorage , every time a relevant view is loaded the data is pulled from database will it increase the overhead as database calls will be made every time that view is loaded. ( Presently the data is pulled from localstorage. )

hi, I am having trouble creating foreign key constraints on the database created with it. I have tried executing query 'PRGAMA foreign_keys = ON' but it is not working. Can anyone suggest me a way to use foreign key constraints with the SQLite plugin.

To share my experiences…

I’ve had similar requirements to yourself (initial DB is 75Mb ish created from an existing sql database). I now have a working solution with an SQLite database. The solution and instructions on how to get it up and running are in this post Prepopulated SQLite Databases in Ionic - #6 by n40jpj

I have used SQL for all of my queries and the following plugin to get the database over to the device in the first instance : GitHub - an-rahulpandey/cordova-plugin-dbcopy: Copy SQLite Database from www folder to default app database location . I haven’t used an ORM, but that’s just because I haven’t looked to find one. I use EF and Hibernate heavily, but I like keeping my plugins to a minimum.

Regarding :

If I use the SQL database the same way I use localstorage , every time a relevant view is loaded the data is pulled from database will it increase the overhead as database calls will be made every time that view is loaded. ( Presently the data is pulled from localstorage. )

That really depends on your coding style and implementation, you can cache the page and or write a service to store some data in memory so that it only gets retrieved from the database when you specifically request it.

There are loads of tools out there for managing SQLite databases free and paid.

The above are my opinions only and suit my requirements, I am however more than happy to discuss better methods.

1 Like

has any one looked into angular-data ?

How does locaForage solve the 5Mb limit? Aren’t all of IndexedDB, WebSQL and localStorage all limited to 5Mb?

If space wasn’t an issue I’d use localStorage but as it is I’m trying to use SQLite which is much higher maintenance. I’ve already created some nice localStorage methods but realised that space would be an issue :frowning:

Wrong, you can now plug it to Sqlite with the Sqlite Cordova Plugin, then : No restriction.

2 Likes

Actually I have, since the time I wrote the post, switched to PouchDB, even without using the sync capabilities it manages the offline part really well and as @ronycohen said you can plug it the SQLite plugin so no 5Mb restriction there.

With that being said I remember that the angular module I talked about in my post: localForage, also had capabilities to plug in another data drivers if I’m not mistaken, but then again I may be wrong.

You should give PouchDB a try. Even without a CouchDB on our server it is an hassle-free SQLite interface for our ionic app.

2 Likes

Is the storage size unlimited?

FYI, SQLite stores data in a file, so ultimately all data comes from a file :smile:

Just want to add some information about local storage and crosswalk
https://lists.crosswalk-project.org/pipermail/crosswalk-help/2014-October/000535.html

I’m using local storage and was worried about size limit, apparently they testet it and were able to save 5200000 characters but not 5300000. For the moment I guess it will be fine, although the performance might be the bigger problem in the end.

Anyone can confirm this?

I have started to use Pouchdb after seeing some people recommend it and it seems to work really well so far! Local storage was my first choice but I was running out of room and Pouchdb solves that using the SQLite plugin

Can you link to a tutorial that shows us how?

go to http://pouchdb.com/guides/

Also managing the conflicts errors is pretty hard.
you need to understand the “revision” way of thinking.

1 Like

I’ve ended up now just using the ngCordova wrapper of pure SQLite now, but using it in a similar way to local storage or Pouchdb where I’ve just got one table where the contents is just key pair values (e.g. column one = ‘user?user1’, column two = json data)

Eliminates all the unnecessary bloat of the pouchdb library!

I was looking for a way to store a few strings on the device that would persist even if the app is removed and installed again. It is possible to achieve this on both iOS and Android but in a different method.

On iOS, using the keychain (https://github.com/shazron/KeychainPlugin) and on Android, using the file plugin and writing to the cordova.file.externalRootDirectory directory.

I wrote an angular service (ng-persist) that has the same API for both platforms and uses the methods above. I also blogged about it in more detail here.

We are using Couchbase Lite :smile:

To be honnest I looked at a lot and I finally made my choice on Pouchdb
Easy to use and integrate. Json file storing. Lot of tutos on the web. :slight_smile: