我试图创建一个准备insert
的续集发言,我就
db[:registration].prepare(:insert)
=> <Sequel::Mysql2::Dataset/PreparedStatement "INSERT INTO `registration` () VALUES ()">
如何创造一个类似如下的声明:
INSERT INTO `registration` (`name`, `email`) VALUES (?, ?)
该文档是有点迟钝,我不能找到任何的例子。
想通了这一点看着自己rspecs:
statement = db[:registration].prepare(:insert, :prepared_statement_name, :email => :$email, :name => :$name)
statement.call(:name => "foo", :email => "foo@bar.com")
注意
传递给键.call
对应于散列传入的值prepare
。 因此,这将工作太:
statement = db[:registration].prepare(:insert, :prepared_statement_name, :email => :$e, :name => :$n)
statement.call(:n => "foo", :e => "foo@bar.com")
ds = db[
"INSERT INTO `registration` (`name`, `email`) VALUES (?, ?)",
name, email
]
ds.call(:insert)