EnglishAdam
EnglishAdam

Reputation: 1390

Persistent data for PhoneGap apps

EDIT#2 - The replies until now (after 2 days) are personal opinions and preferences and not an analysis of the various options that an offline-phoneGap app has to store simple data easily across all relevant devices. As such I haven't accepted any answer, but I am following this question.

I am a little confused about which format of persistent data I should be looking into for a PhoneGap web app I'm building. I've been researching this but things are not clear given my mediocre requirements.

The app is an educational app with about 100 or so multiple choice questions and some memorization games attached.

The app once downloaded can remain offline.

It is for all phonegap supported devices.

The only data that I want to read and write is the user's performance, number of times wrong in total, per card etc and any high scores for games.

This is all very basic information and could be held in very simple js objects.

I would like it to be a fairly simple solution and very easy to maintain/repeat.

What would be my best option? The phonegap file api? json/lawnchair? local-storage? cookies? Would there be a way to 'update' the app and keep it as an object in the javascript? websql? sqilite? Storage API?

Some of these seem overkill.

EDIT Are there differences in devices and I should do some device detection and use different technologies?

Upvotes: 11

Views: 6871

Answers (5)

Tyler Collier
Tyler Collier

Reputation: 11990

It looks like these are good ones, though I haven't tried them.

If you're using the ionic framework which uses AngularJS, I like ngStorage. This one I have tried and it's awesome.

Upvotes: 2

Booker
Booker

Reputation: 766

Phonegap has local storage support for SQL Lite http://docs.phonegap.com/en/2.2.0/cordova_storage_storage.md.html#Storage

Sorry I don't have more info. I was interested in this topic and happened to come across it.

Upvotes: 0

Kyaw Tun
Kyaw Tun

Reputation: 13131

How about try out my library http://dev.yathit.com/ydn-db/getting-started.html backed by IndexedDB (excellent performance, query by index scan), WebSQL (good performance, SQL query) or localStorage (fair performance, no query, get by key, 2.5 MB limit).

db = new ydn.db.Storage('test-store');

db.put('store1', {test: 'Hello World!'}, 123);

req = db.get('store1', 123);
req.done(function(record) {
  console.log(record);
});

High performance while still go easy.

Don't like library dependency, take raw source code at https://bitbucket.org/ytkyaw/ydn-db

Upvotes: 4

noway
noway

Reputation: 2585

I use localStorage to keep my persistent data, but it is somehow not reliable. I have seen some data lost, but I don't know why. But my persistent data usage is not that critical so I don't mind these inconsistencies.

But your case seems more important. I would store my persistent data in Documents folder, with File API.

Upvotes: 1

Devgeeks
Devgeeks

Reputation: 5647

I personally like localStorage. It's straight forward and works great for most situations.

If you are just recording the data you mention above, localStorage would be perfect. I would just seralise your data objects by turning them into a string using say JSON.stringify(), then when pulling it back in use JSON.parse() to turn it back into a useable JS object.

Upvotes: 7

Related Questions