mmon;
use Scalar::Util qw( blessed );
use DB::Object::Cache::Tables;
use DBI;
use JSON;
use Module::Generic::File qw( sys_tmpdir );
use Module::Generic::Global qw( :const );
$self->{cache_table} = 0;
$self->{driver} = '';
# Auto-decode json data into perl hash
$self->{auto_decode_json} = 1;
$self->{auto_convert_datetime_to_object} = 0;
$self->{allo
t_scalar( 'auto_convert_datetime_to_object', @_ ) ); }
sub auto_decode_json { return( shift->_set_get_scalar( 'auto_decode_json', @_ ) ); }
sub attribute($;$@)
{
my $self = shift( @_ );
# $h
r to represent the constant
=item * C<name>
The constant name, e.g. C<PG_JSONB>
=item * C<type>
The data type, e.g. C<jsonb>
=back
=head2 check_name
Sets or gets the optional name of the check
ject which is a L<DB::Object::Tables> object.
=head2 type
Returns the field type such as C<jsonb>, C<json>, C<varchar>, C<integer>, etc.
See also L</constant> for an even more accurate data type, a
> 'strict' ) &&
( $fo->type eq 'jsonb' || $fo->type eq 'json' ) )
{
my $this_json = $self->_encode_json( $value );
$const = $fo->datatype
stant;
$elem->format( sprintf( "$field=%s", $tbl_o->database_object->quote( $this_json, $const ) ) );
}
elsif( $tbl_o->database_object->placeholder->has( $self-
{
foreach my $json_key ( keys( %$value ) )
{
my $json_value = $value->{ $json_key };
# Assu
pe => 'int',
},
json => {
constant => '',
name => 'SQL_UNKNOWN_TYPE',
re => qr/^(json)\b/,
type => 'json',
},
linestring
Object;
my $dbh = DB::Object->connect({
driver => 'mysql',
conf_file => 'db-settings.json',
database => 'webstore',
host => 'localhost',
login => 'store-admin',
debug => 3
a( $elem->fo => 'DB::Object::Fields::Field' ) &&
( $elem->fo->type eq 'jsonb' || $elem->fo->type eq 'json' ) &&
$self->_is_hash( $binded[$i] => 'strict' ) )
{
een}", $binded[$i], "{/} into a JSON string." );
# try-catch
local $@;
my $json = eval
{
$self->new_json->encode( $binded[$i] );
ed( 'DB::Object' ) );
}
else
{
$binded[$i] = $json;
}
}
# If the value provided is a DateTime object without a formatter
an hash of constant value and constant name:
# field => { constant => 12, name => PG_JSONB, type => 'jsonb' };
$self->{types_const} = {};
# The table type. It could be table or view
n => { constant => 17, name => 'PG_JSONB', type => 'jsonb' }
This is used to help manage binded value with the right type, or helps when converting an hash into json.
If nothing is found, it returns
},
json => {
constant => '',
is_array => 0,
name => 'PG_JSON',
re => qr/^json\b/,
type => 'json',
},
jsonb => {
me => 'PG_JSONB',
re => qr/^jsonb\b/,
type => 'jsonb',
},
# <https://www.postgresql.org/docs/current/datatype-json.html#DATATYPE-JSONPATH>
jsonpath => {
nstant => '',
is_array => 0,
name => 'PG_JSONPATH',
re => qr/^jsonpath\b/,
type => 'jsonpath',
},
line => {
constant => '',
L_UNKNOWN_TYPE', type => 'multicurve' },
qr/^(json)\b/ => { constant => '', name => 'SQL_UNKNOWN_TYPE', type => 'json' },
};
our $DEBUG = 0;
our $VERSION = 'v
andler was provided to convert data from json to perl." ) );
# my $data = $opts->{data} || return( $self->error( "No data was provided to convert from json to perl." ) );
return( $opts->{data}
ata->{ $names->[ $i ] } = $dt;
}
}
}
return( $data );
}
sub _convert_json2hash
{
my $self = shift( @_ );
my $opts = $self->_get_args_as_hash( @_ );
# $self->de
andler was provided to convert data from json to perl." ) );
# my $data = $opts->{data} || return( $self->error( "No data was provided to convert from json to perl." ) );
return( $opts->{data}
pe is json, so we transform this value into a json data
elsif( $self->_is_hash( $value => 'strict' ) && ( lc( $types->{ $field } ) eq 'jsonb' || lc( $types->{ $field } ) eq 'json' ) )
my $this_json = $self->_encode_json( $value );
# push( @format_values, $tbl_o->database_object->quote( $this_json, ( lc( $types->{ $field } ) eq 'jsonb' ? DBD::Pg::PG_JSONB : DBD::
ject->quote( $this_json, { pg_type => $self->database_object->get_sql_type( $types->{ $field } ) } ) );
$elem->format( $tbl_o->database_object->quote( $this_json, { pg_type => $sel
ict;
use warnings;
use parent qw( Module::Generic );
use vars qw( $VERSION );
use JSON;
use Fcntl qw( :flock );
use Module::Generic::File qw( sys_tmpdir );
our $VERSION = '
;
$self->{cache_dir} = sys_tmpdir();
$self->{cache_file} = "$self->{cache_dir}/sql_tables.json";
$self->{timeout} = 86400;
$self->SUPER::init( @_ );
$self->{updated} = '';
$sel
my $v = shift( @_ );
$self->{cache_dir} = $v;
$self->cache_file( "$v/sql_tables.json" );
}
return( $self->{cache_dir} );
}
sub cache_file
{
my $self = shift( @_ );
i
my $dbh = DB::Object->connect({
driver => 'SQLite',
conf_file => 'db-settings.json',
database => 'webstore',
host => 'localhost',
login => 'store-admin',