Sunday, 18 August 2013

How to get records from SQLite in random order using the Sequel ORM?

How to get records from SQLite in random order using the Sequel ORM?

Trying to convert this SQLite query
SELECT * FROM `terms` ORDER BY RANDOM() LIMIT 10
to work with a Seqel model. The closest I got:
Term.order(rand{}).limit(10)
Term.order('random ()').limit(10)
which translate into
<Sequel::SQLite::Dataset: "SELECT * FROM `terms` ORDER BY
0.6160215951854449 LIMIT 10">
<Sequel::SQLite::Dataset: "SELECT * FROM `terms` ORDER BY 'random ()'
LIMIT 10">
but neither works. Is there a way to pass a SQLite- or other
database-specific functions to Sequel's order()?

No comments:

Post a Comment