Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Using Appery Model

Hello,
I am trying to implement a feature into my app that requires handling lots of data locally. User story is as follows:
1) User must be able to save to local device (not do DB) no less than 10 different meal sets.
2) Each meal set has 5 separate properties.
3) Each meal may consist of up to 7 food components.
4) Each food component has 5 separate properties.

As you can see it would require more than a hundred of separate local storage variables to handle this scenario and would be ineffective.

I tried to use Appery Model and created such structure:

Image

with local storage variable called FoodSet:

Image

I have read this tutorial here: https://devcenter.appery.io/documenta...
but somehow I am not sure if this approach is correct. My question is how can I save data that does not come from database but is generated locally on the device into Appery Model via JavaScript?
I am aware that there is GET, SET, and UPDATE in Appery API but I can't see directly how could I use it in my scenario.

I would greatly appreciate any guidance.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Using Appery Model

Hello,

You are able to set any JS object to the storage variable. E.g.:

prevar FoodSet = [
{FootSetName:"one", ItemCount:1},
{FootSetName:"two", ItemCount:2}
];
Apperyio.storage.FoodSet.set(FoodSet);
/pre

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Using Appery Model

Ok. It is getting more clear now but let me ask some more questions.
As I understand for now using SET overwrites variable value completely. So the goal here is to keep the complete object containing all data in one variable? Right?

What if I would like to for example:
1) add next FoodSet? FootSetName:"three"?
2) update number of items in FoodSet "one"?

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Using Appery Model

Hi Appery. Some more tips perhaps? I would greatly appreciate your help on that.

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Using Appery Model

Please use method update() for that: https://devcenter.appery.io/documenta...

Adam Garbinski
Posts: 0
Joined: Sat Sep 28, 2013 5:33 pm

Using Appery Model

Thanks Sergiy but as I understand you can update existing object values but not create new one. How exactly should I use it? Like this?

var FoodSet = [
{FootSetName:"three", ItemCount:3}
];
Apperyio.storage.FoodSet.update(FoodSet);

Serhii Kulibaba
Posts: 150
Joined: Tue Aug 27, 2013 1:47 pm

Using Appery Model

If you need to set storage variable, please use JS below:
prevar FoodSet = [
{FootSetName:"one", ItemCount:1},
{FootSetName:"two", ItemCount:2}
];
Apperyio.storage.FoodSet.set(FoodSet);/pre

If you need to update only one it's value, e.g. "one" to "three", please use method update:
preApperyio.storage.FoodSet.update("$[0]['FootSetName']", "three")/pre

here 0 - index of the item to update
FootSetName - name of the parameter to update

Return to “Issues”