Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 如何使用Sequel ORM以随机顺序从SQLite获取记录?_Ruby_Sqlite_Sequel - Fatal编程技术网

Ruby 如何使用Sequel ORM以随机顺序从SQLite获取记录?

Ruby 如何使用Sequel ORM以随机顺序从SQLite获取记录?,ruby,sqlite,sequel,Ruby,Sqlite,Sequel,正在尝试转换此SQLite查询 从'terms'中选择*按随机顺序()限制10 使用续集模型。我得到的最接近的结果是: Term.order(rand{}).limit(10) 术语。顺序('random()')。限制(10) 翻译成 但两者都不起作用。是否有方法使用表达式将SQLite或其他特定于数据库的函数传递给Sequel的order()?: Term.order(Sequel.lit('RANDOM()')).limit(10) 您与Term.order(rand{}).li

正在尝试转换此SQLite查询

从'terms'中选择*按随机顺序()限制10
使用续集模型。我得到的最接近的结果是:

Term.order(rand{}).limit(10)
术语。顺序('random()')。限制(10)
翻译成


但两者都不起作用。是否有方法使用表达式将SQLite或其他特定于数据库的函数传递给Sequel的
order()

Term.order(Sequel.lit('RANDOM()')).limit(10)


您与
Term.order(rand{}).limit(10)
非常接近。但是您需要通过一个块传递它,
Term.order{rand{}}.limit(10)
。在当前版本中,您将使用
Term.order{rand.function}.limit(10)
。请参阅。@DwayneCrooks调用
Term.order{rand.function}
导致
Sequel::DatabaseError:SQLite3::SQLException:没有这样的函数:rand
,因为
rand
不是SQLite函数,而是
Term.order{random.function}
起作用。谢谢你的提示。