I would like to know the correct way to delete an entry from the hstore.

When I fetch user3 below, I wrap the hstore as an hstore_op as described 
here: 
https://github.com/jeremyevans/sequel/blob/master/lib/sequel/extensions/pg_hstore_ops.rb
However, neither of the deletion methods seem to work.

With user4m, I wrap with hstore, though I believe this is redundant. The 
deletion works -- I presume via the underlying hash -- but then the updated 
hstore can't be persisted.

I presume there's an underlying model of how this stuff should fit together 
and work coherently, but I can't figure it out. Some clarification would be 
appreciated..


DB.extension :pg_hstore
Sequel.extension :pg_hstore_ops

  def test_hstore
    UserTimezone.unrestrict_primary_key
    UserTimezone.create(code: 'London', text: '(GMT) London', time_offset: 
0)
    uname = 'somebody'
    User.create(uname: uname, business: false)

    assert_kind_of User, user = User.find(uname: uname)
    assert_equal({}, user.encounter)
    assert_kind_of User, user.update(encounter: {name: 'Fred Blogz', 
address: 'Somewhere'})

    assert_kind_of User, user2 = User.find(uname: uname)
    assert_kind_of Sequel::Postgres::HStore, res2 = user2.encounter
    assert_equal({"name"=>"Fred Blogz", "address"=>"Somewhere"}, 
res2.hstore)
    update2 = res2.merge({new: 'hello'})
    assert_kind_of User, user2.update(encounter: update2)

    assert_kind_of User, user3 = User.find(uname: uname)
    assert_kind_of Sequel::Postgres::HStoreOp, res3 = 
Sequel.hstore_op(user3.encounter)
    assert_kind_of Sequel::SQL::Function, res3.keys
    assert_equal ["new", "name", "address"], user3.encounter.keys
    assert_equal({"name"=>"Fred Blogz", "address"=>"Somewhere", 
"new"=>"hello"}, res3.value)
    assert_kind_of(Sequel::Postgres::HStoreOp, res3 - :new)
    assert_equal({"new"=>"hello", "name"=>"Fred Blogz", 
"address"=>"Somewhere"}, res3.value)
    assert_kind_of(Sequel::Postgres::HStoreOp, res3.delete(:new))
    assert_equal({"new"=>"hello", "name"=>"Fred Blogz", 
"address"=>"Somewhere"}, res3.value)
    assert_kind_of(Sequel::Postgres::HStoreOp, a = res3.delete(:new))
    assert_kind_of Sequel::SQL::Function, a.value
    assert_kind_of Sequel::Postgres::HStoreOp, a.hstore
    assert_kind_of Sequel::SQL::Function, a.hstore.value
    assert_kind_of Sequel::Postgres::HStoreOp, res3
    assert_kind_of Sequel::SQL::Function, res3.keys
    assert_equal ["new", "name", "address"], user3.encounter.keys

    assert_kind_of User, user4 = User.find(uname: uname)
    assert_kind_of Sequel::Postgres::HStore, res4 = 
Sequel.hstore(user4.encounter)
    assert_equal({"name"=>"Fred Blogz", "address"=>"Somewhere", 
"new"=>"hello"}, res4.hstore)
    # assert_kind_of(Sequel::Postgres::HStore, res4 - :new)   # undefined
    assert_kind_of(String, res4.delete(:new))
    assert_equal({"name"=>"Fred Blogz", "address"=>"Somewhere"}, 
res4.hstore)
    assert_kind_of NilClass, user4.update(encounter: res4)

    assert_kind_of User, user5 = User.find(uname: uname)
    assert_kind_of Sequel::Postgres::HStore, res5 = 
Sequel.hstore(user5.encounter)
    assert_equal({"new"=>"hello", "name"=>"Fred Blogz", 
"address"=>"Somewhere"}, res5.hstore)
  end

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to