Page 1 of 1

Random access database. How to 'lucky dip' from a collection of items.

Posted: Tue Feb 11, 2014 2:32 pm
by Simeon Courtie

How can I create a random access database?
I've got Appery to 'invoke a service', accessing a restservice database (as per the tutorial). In my app, I'd like a button click to request a random item of data from this database collection, rather than always the first item, or the entire list.
If there's not a quick way, can I do it via a random number generator, and rename each item's _id value to correspond to numbers 1-1000, say?


Random access database. How to 'lucky dip' from a collection of items.

Posted: Tue Feb 11, 2014 2:50 pm
by Maryna Brodina

Hello! You can't generate _id, but you can generate random number to skip firsn N records in request. Here is more information http://docs.appery.io/documentation/b... (Pagination)


Random access database. How to 'lucky dip' from a collection of items.

Posted: Tue Feb 11, 2014 3:02 pm
by Simeon Courtie

Nice! Thanks very much.


Random access database. How to 'lucky dip' from a collection of items.

Posted: Tue Feb 11, 2014 3:54 pm
by Simeon Courtie

I've got that skip command working fine. Next question - how do I get my random number (generated using arc4random_uniform(N) I assume) into the skip value? I can't find a way of accessing the code within Appery.


Random access database. How to 'lucky dip' from a collection of items.

Posted: Tue Feb 11, 2014 6:17 pm
by Kateryna Grynko

Hi Simeon,

You can save a random value in a localStorage variable, and then map it to a parameter 'skip'.