Im trying to select random datasets with DataMapper, but seems like there is no such function support.
For example, i have set of data:
+-------------------+
| ID | Name | Value |
+-------------------+
| 1 | T1 | 123 |
| 2 | T2 | 456 |
| 3 | T3 | 789 |
| 4 | T4 | 101 |
| ----------------- |
| N | Tn | value |
There can be a lot of data, more than 100k rows.
And i need to map data to object:
class Item
include DataMapper::Resource
property :id, Serial
property :name, String
property :value, String
end
So, the question is: How to select random data from table?
Similar query in SQL will be:
SELECT id, name, value FROM table ORDER BY RAND() LIMIT n;