Best practise for storing data?

Hi,

I am writing an app that allows people to add entries to a tableview and then add detail to to each element of the table view, for example

item1

     data1

     data2

item2

     data1

     data2

I plan to write this out to a JSON file (and read back in on load) but I was wondering what the best method to store this in memory, ie.

Should I create a table variable and as they add each tableview row, add a new table to the table and store the data1, data2 etc into that new table so…

items = {}

items[1].data = {}

items[1].data[1] = data1

items[1].data[2] = data2

items[2].data = {}

items[2].data[1] = data1

items[2].data[2] = data2

So build that structure in real time then dump the table to a JSON file?

Thanks for your help!

    

@Dweezil,

I’m not sure what you mean by best: Fastest, easiest to implement, easiest to understand, saves most spaces, …

Regardless, I would suggest storing your data in a table as you showed above,  It is relatively straight forward, easy-to-modify, quick to access, and easy to store via JSON.

That said, if you are going to build up really large amounts of data, it might be worth learning to use SQL instead.  

In 90% of cases I find myself using tables to store and access data in memory, and json to encode/decode for persistent storage and retrieval.  The other 10% (i.e. rarely) I use SQL.

I hope this helps answer your question.

Note: On tomorrow’s (June 17th) Corona Geek I will be talking about a bench marking suite I’ve been working on.  In this suite, I have some tests that examine tables in terms of creation cost (size and speed).  It might be useful to you.  I should have slides to post with the show.

Cheers,

Ed

Thanks.

In this instance by “best” I suppose I meant most suitable.   I won’t be storing vast amounts of data and fastest isn’t a requirement so it was easiest to implement/understand.

I had thought tables and JSON was the best fit here but wanted confirmation on how to implement it.   So thank you for the guidance.   

Will check out your slides.    Thanks again!

@Dweezil,

I’m not sure what you mean by best: Fastest, easiest to implement, easiest to understand, saves most spaces, …

Regardless, I would suggest storing your data in a table as you showed above,  It is relatively straight forward, easy-to-modify, quick to access, and easy to store via JSON.

That said, if you are going to build up really large amounts of data, it might be worth learning to use SQL instead.  

In 90% of cases I find myself using tables to store and access data in memory, and json to encode/decode for persistent storage and retrieval.  The other 10% (i.e. rarely) I use SQL.

I hope this helps answer your question.

Note: On tomorrow’s (June 17th) Corona Geek I will be talking about a bench marking suite I’ve been working on.  In this suite, I have some tests that examine tables in terms of creation cost (size and speed).  It might be useful to you.  I should have slides to post with the show.

Cheers,

Ed

Thanks.

In this instance by “best” I suppose I meant most suitable.   I won’t be storing vast amounts of data and fastest isn’t a requirement so it was easiest to implement/understand.

I had thought tables and JSON was the best fit here but wanted confirmation on how to implement it.   So thank you for the guidance.   

Will check out your slides.    Thanks again!