What persistent data storages should i use?

hey,

my app has a list with entries that each contain a few strings and ints, i have to be able to update them

how should i store that? my only knowledge so far is server side sql so that i have no idea what else is possible

im already googling a lot about phonegap/cordova and persistent data storage but maybe theres something more useful or more elegant with angular/ionic?

thanks

7 Likes

you can use localStorage for just a few strings and ints:

http://docs.phonegap.com/en/3.0.0/cordova_storage_storage.md.html#localStorage

if im not mistaken i have to read the whole array every time (thats saved in localstorage), find the entry i want to update a part of, change that and overwrite the whole array in localstorage with the new one, same if i add a new object, is that correct?

wouldnt that be a bad choice for id say up to 300 entries (for the beginning)?

I personnaly use Cordova SQLite Plugin which allows me to rely on SQL to persist / retrieve my data.

2 Likes

Hi
I am also trying to solve same problem , i have couple of questions.
Does your app has authentication ,if yes how are u storing user information ?
What happens to data in localstorage when new version of app is installed ?

Thanks

i dont use authentication atm and at least for development the old entry can be accessed by newer versions

but i dont know what its linked to (its not global i hope?) so you should test that for production if you rename your app or do something else

its also very annoying because i had to write something to take care of overseen new assignments without reading the old key first so that i dont delete everything in there

maybe theres some libraries out there for that? ill test lawnchair next so that might fix a few things here and there

1 Like

hi
I think that you should check pouchdb.com

you can use it as local db but it has nice sync functionality too which can be useful

2 Likes

Would agree with @jgx that the Cordova SQLite Plugin is a great option.

I have been using localForage in all of my recent projects. They also have an Angular service/directive available. Havenā€™t had any need for syncing with these recent projects.

Also consider

Iā€™ve used both and like both.

1 Like

I am trying to solve the same problem. I like that Angular remains flexible on data persistence solutions, it makes sense since it is a web framework not specifically a Hybrid app frameworkā€¦ would love to know how people are solving this.

Hereā€™s an overview:

Requirements

  1. Add local database to app build for preloaded data. This will be over the 5MB data limit.
  • Load data from local database on startup.
  • Saving updated data to local data store for persistence.
  • Prefer schema-less if possible.
  • Simple query interface. I could load all the data into memory and just use standard Angular filters for this, provided the performance was decent.
  • Object query interfaceā€¦ something like an ActiveRecord-like ORM rather than having to write SQL in my app.
  • Future proof. I donā€™t want to reinvent the wheel every time I am building an app that needs data persistence. Iā€™d like to choose a solution that allows me for basic query interface, large data storage up front.

Options

Iā€™ve been looking at the following options. Can you provide any feedback on any of these?

  1. Breezejs - Looks more focused on server. Is there an SQLite interface?
  • YDN-DB - Seems like an option.
  • JayData - Is this still active? Concerned about commercial aspect of it.
  • Persistencejs - This looks promising. Is the project still active?
  • ngStorage - is this just a localStorage interface? Does it solve the 5M limit?
  • Angular-cache - Can I have data to pre-load with this? How long can I persist data?
  • localForage - donā€™t know much about this. Does it solve the 5M limit?
  • Pouchdb - concerned about query language. does not solve 5M restriction
  • Couchdb Lite - concerned about query language.
  • WebSQL - I donā€™t to use this since it seems like it is on the way outā€¦ plus 5M limit.
  • Indexeddb - There is a shim that builds compat-layer for most major browsers. 5M limit. If I could use this on top of Sqlite that would prob be a winner for me since more standards based.
  • Store in json file - Just use plain old objects and then use Phonegap file api to load and store serialized data. Seems like a pain to have to serialize all the data every time we want to saveā€¦ but an option so long as I can use Angular filters.

Sorry for the long post. I really would like to see some thoughts on best practices. Would love an Angular/Ionic Way to handle large data persistence.

Thanks

4 Likes

PouchDB + GQL plugin (for query interface) + SQLite plugin and you havenā€™t 5MB quota

I use WEB SQL Database to store data in my app. If you have C#/ Entity Framework background you should familiarize yourself with HTML5 SQLite for PhoneGap/Cordova. This library is very similar to EF. It offers: Code First Mode, Data Migrations, Repositories, Linq-like query etc.

Very interesting. I was not aware of the GQL plugin. Do you think this would be fine for a Phonegap / Cordova app? Iā€™ll be testing tomorrow.

@kevbaker Have you tested GQL? Does it meet your 7 requirements?
Also what about Cordova SQLite Plugin?

I also have the same problem. Now I am using localStorage for simplicity.
However, it is not only limited on size, but also not persistent if the users just re-install the app instead of upgrading.

Hello,
i have a litte trick for my News to save it like for offline view.

I use the Cordova File plugin ( https://build.phonegap.com/plugins/617 ).
I save all my news in json format into a file on the device.
And if a close and open the device or reinstall the app, the file is always there because u can save the file persistent.
I must only read the file and json parse it again.

Hope it helps

4 Likes

Yes, this is an option.

What about the performance, if there are hundreds of pieces of news?

Sometimes only a few pieces (say 10) should be read into the view.
But I guess it is difficult with the FileReader API to locate and load any 10 pieces into the view.

Another issue is privacy, if the data is not just news.
Of course, we can encrypt the file.
But it is better if the user does not have to memorize and input some password.

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. )