我从Ruby的Sequel数据库库开始.
给出以下代码:
require 'sequel' db = Sequel.connect('sqlite://users.db') users = db[:users] users.first.delete
Ruby抛出错误:
'delete' : wrong number of arguments (0 for 1) (ArgumentError)
我可以删除多条记录,但.first.delete
不起作用.怎么了?
db[:users]
给你一个Sequel::SQLite::Dataset
.没有任何参数的users.first
方法会将用户作为Hash
对象.现在你正在打电话Hash#delete
,这需要一个参数.但你并没有传递那个论点.因此它抱怨.
而是做如下:
# if you want to delete the the first matching argument of any specific # attribute/db column db[:users].filter(:key => 1).delete # or if you want to delete the first record from db db[:users].limit(1).delete
也阅读此#drop
方法.