我正试图在续集中创建一个准备好的insert
语句,我就是
db[:registration].prepare(:insert)
=> <Sequel::Mysql2::Dataset/PreparedStatement "INSERT INTO `registration` () VALUES ()">
如何创建类似于以下内容的语句:
INSERT INTO `registration` (`name`, `email`) VALUES (?, ?)
文档有点迟钝,我在网上找不到任何示例。
答案 0 :(得分:4)
看看他们的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")
答案 1 :(得分:0)
ds = db[
"INSERT INTO `registration` (`name`, `email`) VALUES (?, ?)",
name, email
]
ds.call(:insert)