:Definition::JSON;
{
$EntityModel::Definition::JSON::VERSION = '0.102';
}
use EntityModel::Class {
_isa => [qw{EntityModel::Definition}],
};
=head1 NAME
EntityModel::Definition::JSON - definitio
SYNOPSIS
See L<EntityModel>.
=head1 DESCRIPTION
See L<EntityModel>.
=head1 METHODS
=cut
use JSON::XS;
=head2 load_file
=cut
sub load_file {
my $self = shift;
my $path = shift;
open my $fh
f = shift;
my %args = @_;
my $path = delete $args{path} or die "No path provided";
my $data = JSON::XS->new->encode($args{structure});
open my $fh, '>:encoding(utf-8)', $path or die "Failed to op
ot edit
this file, but rather the original, inline with EntityModel::Definition::JSON
at lib/EntityModel/Definition/JSON.pm
(on the system that originally ran this).
If you do edit this file, and don'
to be removed, make
sure you change the first line.
=cut
=head1 NAME
EntityModel::Definition::JSON - definition support for L<EntityModel>
=head1 VERSION
version 0.102
=head1 SYNOPSIS
See L<En
to a file.
=head2 save_string
Return output as a scalar.
=head2 parse
Create and parse the L<JSON::XS> object.
=head1 INHERITED METHODS
=over 4
=item L<EntityModel::Definition>
L<add_entity_t
2
=head1 SYNOPSIS
use EntityModel;
# Define model
my $model = EntityModel->new->load_from(
JSON => { entity : [
{ name : 'article', field : [
{ name : 'idarticle', type : 'bigserial' },
s:
=over 4
=item * Type - must be a valid L<EntityModel::Definition> subclass, such as 'Perl', 'JSON' or 'XML'.
=item * Definition - dependent on the subclass, typically the filename or raw string
name => 'value', type => 'varchar' },
],
],
}
);
or the equivalent from JSON:
$model->load_from(
JSON => \q{
"name" : "kvstore",
"entity" : [
"name" : "object",
"primary"
create tutorial.json
Add an entity:
entitymodel edit tutorial.json add entity name=something auto_primary=true
Add a field to an existing entity:
entitymodel edit tutorial.json entity something
utorial.json entity something add field name=unwanted type=text
entitymodel edit tutorial.json entity something remove field name=unwanted
Display the model:
entitymodel show tutorial.json
=head2
orial.json insert ...
=head2 Integrating with other systems
If you already have SQL schema as a starting point, you can import this and
generate a new model.
entitymodel import tutorial.json from
ss {
model => { type => 'EntityModel::Model' },
};
use EntityModel;
use EntityModel::Definition::JSON;
use EntityModel::Definition::XML;
use Module::Load;
=head1 NAME
EntityModel::App - interface t
.json$/) {
$model->load_from(
JSON => { file => $file }
);
} elsif($file =~ /\.xml$/) {
$model->load_from(
XML => { file => $file }
);
} else {
die "Unknown extension, expected .json
elf->show_model;
},
'export' => sub {
my $self = shift;
my $def = EntityModel::Definition::JSON->new;
$def->model($self->model);
print $def->save(string => '');
},
'merge' => sub {
my
2
=head1 SYNOPSIS
use EntityModel;
# Define model
my $model = EntityModel->new->load_from(
JSON => { entity : [
{ name : 'article', field : [
{ name : 'idarticle', type : 'bigserial' },
s:
=over 4
=item * Type - must be a valid L<EntityModel::Definition> subclass, such as 'Perl', 'JSON' or 'XML'.
=item * Definition - dependent on the subclass, typically the filename or raw string
name => 'value', type => 'varchar' },
],
],
}
);
or the equivalent from JSON:
$model->load_from(
JSON => \q{
"name" : "kvstore",
"entity" : [
"name" : "object",
"primary"