Hi,
I have a JSONB column in my model. in that column I store a hash. An ID
points to a value. So a basic example of my Hash is...
'{ "111' => 1, '2222' => 2, '321' => 33 }'
The messy part for me is getting at the values... by searching for the key.
I am not sure I am liking my approach, so am looking for something clean...
My JSONB Column is :number_sold, so I start with a simple assignment:
*jb = Sequel.pg_jsonb_op(:number_sold)*
Now I want to do a query on my Model for the key I am interested in, say
'2222', and I want that value, 2.
If I run the following query it works where an item.product_id will be 2222.
*MyModel.select(jb.get_text(item.product_id.to_s)).first!.values[:"?column?"]*
Sequel returns an object with @values set to :"?column?" => "2"
So this is now... ugly as heck in my books... is there a more elegant way
to store a key:value pair in PG and use Sequel to view/update the hash...
it seems to work fine... but I am not comfortable with this
.first!.values[;"?column?"] business.
Excuse my beginners luck with Sequel... just looking for some veteran
wisdom here!
Thanks for any help.
Dave
--
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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.