Simeon Courtie
Posts: 0
Joined: Tue Feb 11, 2014 2:32 pm

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

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

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

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)

Simeon Courtie
Posts: 0
Joined: Tue Feb 11, 2014 2:32 pm

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

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.

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

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

Hi Simeon,

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

Return to “Issues”