Hi monks.

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:
Column | Type | Modifiers + --------+---------+--------------------------------------------------- +--- id | integer | not null default nextval('details_id_seq'::regclas +s) data | jsonb |
Dancer2 code:
... 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' };
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?

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.


In reply to Using DBIx Class with json data types by epoch1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.