Discussion:
JSON support for Mojo::Pg
(too old to reply)
sri
2014-12-31 00:09:32 UTC
Permalink
JSON support in PostgreSQL 9.4 is pretty awesome, and i'd love to make it
easier to use with Mojo::Pg.

https://gist.github.com/anonymous/7409f3d24ae26208d533

But i'm not sure yet what that should look like, this partial patch is just
one possibility.

# JSON roundtrip
$db = $pg->db;
is_deeply $db->json({bar => 'baz'})->query('select ?::json as
foo')->hash,
{foo => {bar => 'baz'}}, 'right structure';

Decoding JSON automatically in Mojo::Pg::Results is mostly a no-brainer,
but where it gets complicated is encoding. DBD::Pg already serializes array
references to native PostgreSQL arrays and simple strings/numbers are also
valid JSON documents. Maybe someone here has an idea for a sleek JSON API?

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2014-12-31 04:33:09 UTC
Permalink
Post by sri
But i'm not sure yet what that should look like, this partial patch is
just one possibility.
And here's a more complete version of the patch.

https://gist.github.com/anonymous/0812a33be995f2a1852f

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2014-12-31 15:48:16 UTC
Permalink
Somehow i expected more interest in PostgreSQL and JSON, but i guess we are
not doing this.

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Roland Lammel
2015-01-02 22:16:21 UTC
Permalink
The JSON functions in pg 9.4 seem to be great, but I guess you are ahead. A
working API would be awesome though, as it basically allows using PG as an
object store with indexing.

I'm definitly interested personally, but did not wrap my head around it
enough to come up with any useful suggestion.

Just to let you know there is interest in that feature suggestion.

+rl
Post by sri
Somehow i expected more interest in PostgreSQL and JSON, but i guess we
are not doing this.
--
sebastian
--
You received this message because you are subscribed to the Google Groups
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
David Stevenson
2015-01-02 23:52:32 UTC
Permalink
Likewise, definite interest here Sebastian (and Roland).

But it’s been the holidays here so I haven’t had a chance to look at anything in detail yet.

David
The JSON functions in pg 9.4 seem to be great, but I guess you are ahead. A working API would be awesome though, as it basically allows using PG as an object store with indexing.…snip...
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2015-01-03 00:12:07 UTC
Permalink
I've been testing some possible JSON APIs in Minion::Backend::Pg, but sadly
they all look much worse than the original.

https://gist.github.com/anonymous/1a6cf290e3e200dd9e71

Making method chains like ->val(...)->json(...)->val(...)->query(...) and
multiline SQL statements work with perltidy just doesn't seem possible.

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2015-01-03 14:48:36 UTC
Permalink
Looks like we have a neat solution after all. :)


https://github.com/kraih/mojo-pg/commit/5ec44181a536288f229077e084abe90d0422c7d6

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2015-01-03 15:22:53 UTC
Permalink
Post by sri
Looks like we have a neat solution after all. :)
And we already had the "dollar_only" method, which allows all JSON
operators to be used.

http://mojolicio.us/perldoc/Mojo/Pg/Database#dollar_only

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
sri
2015-01-03 23:50:10 UTC
Permalink
And released with Mojo::Pg 1.07. :)

# JSON roundtrip
say $db->query('select ?::json as foo', {json => {bar => 'baz'}})
->expand->hash->{foo}{bar};

--
sebastian
--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...