Skip to content

Commit

Permalink
fix a few JSON encoding and decoding issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 17, 2015
1 parent 6d6d6c3 commit 6dcc2a7
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

2.07 2015-06-16
2.07 2015-06-17
- Fixed a few JSON encoding and decoding issues.

2.06 2015-06-07
- Fixed bug in Mojo::Pg::Database where sequential non-blocking queries would
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Pg/Database.pm
Expand Up @@ -4,7 +4,7 @@ use Mojo::Base 'Mojo::EventEmitter';
use Carp 'croak';
use DBD::Pg ':async';
use Mojo::IOLoop;
use Mojo::JSON 'encode_json';
use Mojo::JSON 'to_json';
use Mojo::Pg::Results;
use Mojo::Pg::Transaction;
use Scalar::Util 'weaken';
Expand Down Expand Up @@ -79,7 +79,7 @@ sub query {
$attrs{pg_placeholder_dollaronly} = 1 if delete $self->{dollar_only};
$attrs{pg_async} = PG_ASYNC if $cb;
my $sth = $self->dbh->prepare_cached($query, \%attrs, 3);
$sth->execute(map { _json($_) ? encode_json $_->{json} : $_ } @_);
$sth->execute(map { _json($_) ? to_json $_->{json} : $_ } @_);

# Blocking
unless ($cb) {
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Pg/Results.pm
Expand Up @@ -2,7 +2,7 @@ package Mojo::Pg::Results;
use Mojo::Base -base;

use Mojo::Collection;
use Mojo::JSON 'decode_json';
use Mojo::JSON 'from_json';
use Mojo::Util 'tablify';

has 'sth';
Expand Down Expand Up @@ -48,7 +48,7 @@ sub _expand {
return @data;
}

sub _json { $_[0] = decode_json $_[0] }
sub _json { $_[0] = from_json $_[0] }

1;

Expand Down
2 changes: 2 additions & 0 deletions t/database.t
Expand Up @@ -148,6 +148,8 @@ is_deeply $results->expand->array, [undef], 'right structure';
is_deeply $results->expand->array, undef, 'no more results';
is_deeply $db->query('select ?::json as unicode', {json => {'' => ''}})
->expand->hash, {unicode => {'' => ''}}, 'right structure';
is_deeply $db->query("select json_build_object('☃', ?::text) as unicode",
'')->expand->hash, {unicode => {'' => ''}}, 'right structure';

# Fork-safety
$dbh = $pg->db->dbh;
Expand Down

0 comments on commit 6dcc2a7

Please sign in to comment.