Two basic questions about operating on results sets with this code:
require 'sequel'
db = Sequel.sqlite
db.create_table :items do
primary_key :id
end
id = 3
item = {:id => 3}
2.times do
items = db[:items]
entries = items.where(:id => id) # fails with "id" instead of :id
if entries.empty?
items << item
else
entries.update item
# is there one operation that works in both cases?
end
p items.to_a
end
(1) why does
entries = items.where("id" => id)
fail, when "id" is apparently an acceptable substitute for :id in #<< ?
(2) Is there a way to express the if... as a single operation, with the
same semantics (i.e. not failing when there's already an entry)?
Thanks!
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---