epoch1 has asked for the wisdom of the Perl Monks concerning the following question:
I'm just getting to grips with DBIx::Class and I'm trying to get it to work with jsonb data types in PostrgeSQL. I've got a simple select statement that returns a json string that I convert into a hash to pass to a template.
Simplified database:Dancer2 code:Column | Type | Modifiers + --------+---------+--------------------------------------------------- +--- id | integer | not null default nextval('details_id_seq'::regclas +s) data | jsonb |
Is there any way I can run queries based on keys/values in the json column using DBIx::Class, for instance where email = 'foo@...', or specifiy which key/vals I want to return?... my $rs = schema->resultset('Detail') ->find({id => route_parameters->get('code')}); if ($rs) { #return to_dumper(from_json($rs->data)); template 'form', {'form' => from_json($rs->data)}; ... Decoded json: $VAR1 = { 'order_code' => '0165-02675-4565', 'email' => +'foo@test.com', 'price' => '15', 'title' => 'Mt Thing XYZ' };
I am doing this as I need a way to handle potentially unstructured data and I am restricted to using Postgres. I'm quite new to DBIx::Class, maybe this isn't the best tool to use in this case but I would appreciate any help.
Just found DBIx::NoSQL, which looks like it might be what I need but the docs say it's still in beta which is a concern.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using DBIx Class with json data types
by erix (Prior) on May 08, 2016 at 23:21 UTC | |
|
Re: Using DBIx Class with json data types
by Your Mother (Archbishop) on May 08, 2016 at 21:12 UTC | |
by epoch1 (Acolyte) on May 09, 2016 at 12:53 UTC | |
|
Re: Using DBIx Class with json data types
by Corion (Patriarch) on May 08, 2016 at 17:47 UTC | |
|
Re: Using DBIx Class with json data types
by Anonymous Monk on Jan 20, 2017 at 10:37 UTC |