Once I get a sequel dataset built, I'd like to pick one element at random from it. What's the best way to do this? Retrieve an array of all the key values and pick one randomly and then filter the entire dataset on that value? Use the limit function with a limit of 1 and an offset of a random number from 0 to the dataset count - 1? Some other way that I'm not thinking of?
(Optional context: I'm working on an automated test suite. I'd like to 1) get my data from the database rather than hard coding it, so that my tests just work in multiple environments with multiple databases, and 2) introduce some variation in the tests so that they don't follow the same path every single time they run (hoping to catch bugs where we aren't aware of an aspect of the data that has an impact rightly or wrongly, and so we didn't plan a test for that particular data aspect). I'm making builder classes that start off with a query that contains all the records of that type (so all the patients in the database initially), then providing methods of the builder that filter down that dataset (so, a patient currently admitted to the hospital, or a patient with an allergy to a medication). These filter methods become chainable to allow for multiple filters to be applied, just like sequel does. Finally, there's some sort of get method that takes that filtered dataset, picks a record from it and builds an instance of the appropriate class, returning it so my tests can use that data. Of course, there'll be error handling for the cases where the dataset gets filtered down to 0 records, at which point I would likely either log the absence and error or simply create a new record, depending on the type of data needed. At the moment, that's out of scope of my question though.) Thanks! Andy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
