# ABSTRACT: JsonSQL distribution. A collection of modules for generating safe SQL from JSON strings.
use strict;
use warnings;
use 5.014;
package JsonSQL;
our $VERSION = '0.41'; # VERSION
1;
AME
JsonSQL - JsonSQL distribution. A collection of modules for generating safe SQL from JSON strings.
=head1 VERSION
version 0.41
=head1 SYNOPSIS
This is a set of modules used to turn a JSON str
esenting an SQL query into an appropriate SQL statement.
For example,
use JsonSQL::Query::Select;
my $jsonString = '{
"fields": [
{"column": "*"}
],
# ABSTRACT: JsonSQL::Param::Order object. Stores a Perl representation of an SQL ORDER BY clause for use in JsonSQL::Query objects.
use strict;
use warnings;
use 5.014;
package JsonSQL::Param::Ord
$VERSION = '0.41'; # VERSION
use List::Util qw( any );
use JsonSQL::Param::Field;
use JsonSQL::Error;
## These are validated by the JSON schema, but an extra check doesn't hurt.
my @validDirs = ('
my $orderField = JsonSQL::Param::Field->new($orderhashref->{field}, $queryObj, $default_table_rules);
if ( eval { $orderField->is_error } ) {
return JsonSQL::Error->new("invalid_f
ABSTRACT: JSON schema validation module. Returns a JsonSQL::Validator object for validating a JSON string against a pre-defined schema.
use strict;
use warnings;
use 5.014;
package JsonSQL::Valida
JSON::Validator;
use JSON::Parse qw( assert_valid_json parse_json );
use List::Util qw( any );
use JsonSQL::Schemas::Schema;
use JsonSQL::Error;
#use Data::Dumper;
sub new {
my ( $class, $json
ified JSON schema.
my $schema = JsonSQL::Schemas::Schema->load_schema($jsonSchema);
if ( eval { $schema->is_error } ) {
return JsonSQL::Error->new("validate", "Error loading JSON schem
# ABSTRACT: JsonSQL::Query::Insert object. Stores a Perl representation of a set of INSERT statements created from a JSON string.
use strict;
use warnings;
use 5.014;
package JsonSQL::Query::Inser
# VERSION
use base qw( JsonSQL::Query::Query );
use JsonSQL::Validator;
use JsonSQL::Error;
use JsonSQL::Param::Insert;
sub new {
my ( $class, $query_rulesets, $json_query, $quote_char ) = @
from JsonSQL::Query::Query base class.
my $self = $class->SUPER::new($query_rulesets, 'insert', $quote_char);
if ( eval { $self->is_error } ) {
return (0, "Could not create JsonSQL IN
# ABSTRACT: JSON query base class. Provides the quote_identifier method for escaping table and column identifiers.
use strict;
use warnings;
use 5.014;
package JsonSQL::Query::Query;
our $VERSION
= '0.41'; # VERSION
use JsonSQL::Validator;
sub new {
my ( $class, $query_rulesets, $json_schema, $quote_char ) = @_;
## DB specific values can be used in the future, but for now we a
> $quoteChar
};
# Get a JsonSQL::Validator object with the provided $json_schema and $query_rulesets.
my $validator = JsonSQL::Validator->new($json_schema, $query_rulesets);
if (
# ABSTRACT: JsonSQL::Query::Select object. Stores a Perl representation of a SELECT statement created from a JSON string.
use strict;
use warnings;
use 5.014;
package JsonSQL::Query::Select;
our
e qw( JsonSQL::Query::Query );
use JsonSQL::Validator;
use JsonSQL::Error;
use JsonSQL::Param::Fields;
use JsonSQL::Param::Field;
use JsonSQL::Param::Tables;
use JsonSQL::Param::Joins;
use JsonSQL::P
aram::ConditionDispatcher;
use JsonSQL::Param::OrderBy;
# Using this as a crutch for now, but will deprecate at some point.
use SQL::Maker::Select;
#use Data::Dumper;
#use constant DEBUG => 0; # tog
# ABSTRACT: JSON schema base class. Used as a dispatcher for loading JSON schema objects used by JsonSQL::Validator.
use strict;
use warnings;
use 5.014;
package JsonSQL::Schemas::Schema;
our $VER
SION = '0.41'; # VERSION
use Class::Load qw( try_load_class );
use JSON::Parse qw( parse_json );
use JsonSQL::Error;
sub new {
my $class = shift;
my $self = {};
bless $self,
class;
return $self;
}
sub load_schema {
my ( $caller, $jsonSchema ) = @_;
my $class = "JsonSQL::Schemas::" . $jsonSchema;
my ( $success, $err ) = try_load_class($class);
ACT: JsonSQL 'select' JSON schema.
use strict;
use warnings;
use 5.014;
package JsonSQL::Schemas::select;
our $VERSION = '0.41'; # VERSION
use base qw( JsonSQL::Schemas::Schema );
my $jsonSche
QL Select Schema",
"id": "sqlSelectSchema",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "JSON schema to describe an SQL SELECT query",
"type": "object",
"p
SUPER::new();
$self->{_json} = $jsonSchema;
return $self;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
JsonSQL::Schemas::select - JsonSQL 'select' JSON schema.
=head1 VERSION
v
ACT: JsonSQL 'insert' JSON schema.
use strict;
use warnings;
use 5.014;
package JsonSQL::Schemas::insert;
our $VERSION = '0.41'; # VERSION
use base qw( JsonSQL::Schemas::Schema );
my $jsonSche
QL Insert Schema",
"id": "sqlInsertSchema",
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "JSON schema to describe an SQL INSERT",
"type": "object",
"propert
SUPER::new();
$self->{_json} = $jsonSchema;
return $self;
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
JsonSQL::Schemas::insert - JsonSQL 'insert' JSON schema.
=head1 VERSION
v
Defines an error object to be used at various stages of JSON validation and SQL generation.
use strict;
use warnings;
use 5.014;
package JsonSQL::Error;
our $VERSION = '0.41'; # VERSION
sub new
NAME
JsonSQL::Error - Defines an error object to be used at various stages of JSON validation and SQL generation.
=head1 VERSION
version 0.41
=head1 SYNOPSIS
To use this:
return JsonSQL::Er
ptions/>
=head1 METHODS
=head2 Constructor new($type, $message)
Instantiates and returns a new JsonSQL::Error object.
$type => Any string to group error messages by.
$message => The