r::JSON;
use strict;
use warnings;
our $VERSION = '0.000004';
use Cpanel::JSON::XS qw/decode_json/;
use Role::Tiny::With qw/with/;
with 'DBIx::QuickORM::Role::Conflator';
my $JSON = Cpanel::JSON::
->allow_nonref(1);
sub JSON { $JSON }
sub qorm_sql_type {
my $class = shift;
my %params = @_;
my $con = $params{connection};
if (my $type = $con->supports_json) {
return $ty
n decode_json($val);
}
sub qorm_deflate {
my $class = shift;
my %params = @_;
my $val = $params{value} or return undef;
return $val unless ref($val);
return $class->JSON->encode(
ckORM::Conflator::JSON::ASCII;
use strict;
use warnings;
our $VERSION = '0.000004';
use parent 'DBIx::QuickORM::Conflator::JSON';
use Cpanel::JSON::XS();
my $ASCII = Cpanel::JSON::XS->new->ascii(1
)->convert_blessed(1)->allow_nonref(1);
sub JSON { $ASCII }
1;
package DBIx::QuickORM::Type::JSON;
use strict;
use warnings;
our $VERSION = '0.000019';
use DBIx::QuickORM::Util qw/parse_conflate_args/;
use Carp qw/croak/;
use Scalar::Util qw/reftype blessed/;
ole::Type';
use Cpanel::JSON::XS qw/decode_json/;
my $JSON = Cpanel::JSON::XS->new->utf8(1)->convert_blessed(1)->allow_nonref(1);
sub JSON { $JSON }
my $CJSON = Cpanel::JSON::XS->new->utf8(1)->conv
ert_blessed(1)->allow_nonref(1)->canonical(1);
sub CJSON { $CJSON }
sub qorm_inflate {
my $params = parse_conflate_args(@_);
my $val = $params->{value} or return undef;
my $class = $p
ckORM::Conflator::JSON::ASCII;
use strict;
use warnings;
our $VERSION = '0.000005';
use parent 'DBIx::QuickORM::Conflator::JSON';
use Cpanel::JSON::XS();
my $ASCII = Cpanel::JSON::XS->new->ascii(1
)->convert_blessed(1)->allow_nonref(1);
sub JSON { $ASCII }
1;
r::JSON;
use strict;
use warnings;
our $VERSION = '0.000005';
use Cpanel::JSON::XS qw/decode_json/;
use Role::Tiny::With qw/with/;
with 'DBIx::QuickORM::Role::Conflator';
my $JSON = Cpanel::JSON::
->allow_nonref(1);
sub JSON { $JSON }
sub qorm_sql_type {
my $class = shift;
my %params = @_;
my $con = $params{connection};
if (my $type = $con->supports_json) {
return $ty
n decode_json($val);
}
sub qorm_deflate {
my $class = shift;
my %params = @_;
my $val = $params{value} or return undef;
return $val unless ref($val);
return $class->JSON->encode(
Carp qw/croak confess/;
use POSIX();
use IO::Select();
use Scope::Guard();
use Cpanel::JSON::XS qw/decode_json/;
use parent 'DBIx::QuickORM::Select';
use DBIx::QuickORM::Util::HashBase qw{
+rea
{ POSIX::_exit(42) };
my $guard = Scope::Guard->new(sub { POSIX::_exit(1) });
my $json = Cpanel::JSON::XS->new->ascii(1)->convert_blessed(1)->allow_nonref(1);
$wh->autoflush(1);
$sel
print $wh $json->encode({cols => $cols}), "\n";
print $wh $json->encode({relmap => $cols}), "\n";
while (my $data = $sth->fetchrow_arrayref) {
print $wh $json->encode({ro
= (
uuid => 'DBIx::QuickORM::Conflator::UUID',
json => 'DBIx::QuickORM::Conflator::JSON',
jsonb => 'DBIx::QuickORM::Conflator::JSON',
map {$_ => 'DBIx::QuickORM::Conflator::DateTime'
conflate($conflate);
if ($conflate eq 'DBIx::QuickORM::Conflator::JSON') {
omit();
}
}
elsif ($col->{is_date
my @depends = qw{
Class::Method::Modifiers
Class::XSAccessor
Cpanel::JSON::XS
DBD::MariaDB
DBD::Pg
DBD::SQLite
DBD::mysql
DBI
our $VERSION = '0.000004';
use parent 'DBIx::QuickORM::DB::MySQL';
use DBIx::QuickORM::Util::HashBase;
sub sql_spec_keys { qw/percona mysql/ }
sub supports_uuid { () }
sub supports_json { () }
1;
b supports_json {
my $self = shift;
my ($dbh) = @_;
return 'JSONB' unless $dbh;
my $ver = $self->db_version($dbh);
my ($maj, $min) = split /\./, $ver;
return 'JSONB' if $maj
my %NORMALIZED_TYPES = (
INT => 'INTEGER',
BINARY => 'BYTEA',
JSON => 'JSONB',
BIGINTEGER => 'BIGINT',
SMALLINTEGER => 'SMALLINT',
TINYINTEGER => 'TI
b supports_json {
my $self = shift;
my ($dbh) = @_;
return 'JSON' unless $dbh;
my $ver = $self->db_version($dbh);
my ($maj, $min) = split /\./, $ver;
return 'JSON' if $maj >
b supports_json {
my $self = shift;
my ($dbh) = @_;
return 'JSONB' unless $dbh;
my $ver = $self->db_version($dbh);
my ($maj, $min) = split /\./, $ver;
return 'JSONB' if $maj
ete $data->{$_} for $self->primary_key_field_list;
# Use dclone in case there is an inflated json object or similar that we do not want shared
$data = dclone($data);
# Add in any overrid
autotype 'UUID'; # Automatically handle UUID fields
autotype 'JSON'; # Automatically handle JSON fields
# Do not autofill these tables
autoskip
database connection fields.
This is mainly useful if you credentials are in an encrypted YAML or JSON file
and you have a method to decrypt and read it returning it as a hash.
db mydb => sub {
ific hook points
};
=item C<autotype $TYPE_CLASS>
=item C<autotype 'JSON'>
=item C<autotype '+DBIx::QuickORM::Type::JSON'>
=item C<autotype 'UUID'>
=item C<autotype '+DBIx::QuickORM::Type::UU
temp_table_supported { 0 }
sub temp_view_supported { 0 }
sub supports_uuid { () }
sub supports_json { () }
sub supports_datetime { 'DATETIME' }
sub supports_async { 0 }
sub async_query_arg { croa
pports_json {
my $self = shift;
my ($dbh) = @_;
return 'JSON' unless $dbh;
my $ver = $self->db_version($dbh);
my ($maj, $min, $rev) = split /[-\.]/, $ver;
return 'JSON' if $
RCHAR(36).
=back
=head3 JSON, JSON::ASCII
This conflator will inflate the JSON into a perl data structure and deflate it
back into a JSON string.
This uses L<Cpanel::JSON::XS> under the hood.
=ov
flator::JSON>
Defaults to C<< $json->utf8->encode_json >>
This produces a utf8 encoded json string.
=item L<DBIx::QuickORM::Conflator::JSON::ASCII>
Defaults to C<< $json->ascii->encode_json >>
Th
is produces an ASCII encoded json string with non-ascii characters escaped.
=back
=head3 DateTime - Will not leave a mess with Data::Dumper!
L<DBIx::QuickORM::Conflator::DateTime>
This conflator w
};
}
return $data;
}
# See the Cpanel::JSON::XS docs
sub FREEZE {
my $self = shift;
my ($serializer) = @_;
return ($self->TO_JSON);
}
sub THAW {
my $class = shift;
my ($
serializer, $data) = @_;
return $class->FROM_JSON($data);
}
sub FROM_JSON {
my $class = shift;
my ($data) = @_;
return $data if $data->{error};
if (my $locator = $data->{locato
my $found = DBIx::QuickORM::GlobalLookup->lookup(@$locator)) {
my $check = $found->TO_JSON;
return {error => "Source content mismatch between origin and local copy (Source obj
;
my $json = Cpanel::JSON::XS->new->utf8(1)->convert_blessed(1)->allow_nonref(1);
my $dbh = $con->aside_dbh;
my ($sth, $res) = $self->_execute($dbh, $sql);
print $wh $json->encode({r
sth, $res, $sql)) {
while (my $row = $fetch->()) {
print $wh $json->encode($row), "\n";
}
}
}
close($wh);
1;
use Test2::V0 -target => 'DBIx::QuickORM::Conflator::JSON';
use ok $CLASS;
done_testing;