EntityModel is a Perl module that provides a data storage abstraction system (in the form of an Object Relational Model) for accessing backend storage from Perl and other languages. The intent is to take a model definition and generate or update database tables, caching layer and the corresponding code (Perl/C++/JS) for accessing data.
SYNOPSIS
use EntityModel;
# Define model
my $model = EntityModel->new->load_from(
JSON => { entity : [
{ name : 'article', field : [
{ name : 'idarticle', type : 'bigserial' },
{ name : 'title', type : 'varchar' },
{ name : 'content', type : 'text' }
], primary => { field : [ 'idarticle' ], separator : ':' }
] }
);
# Apply PostgreSQL schema (optional, only needed if the model changes)
$model->apply('PostgreSQL' => { schema => 'datamodel', host => 'localhost', user => 'testuser' });
# Create Perl classes
$model->apply('Perl' => { namespace => 'Entity', baseclass => 'EntityModel::EntityBase' });
my $article = Entity::Article->create(
title => 'Test article',
content => 'Article content'
)->done(sub {
my $article = shift;
say "ID was " . $article->id;
})->fail(sub {
die 'Failed to create new article';
});
Entity::Article->find(
title => 'Test article'
)->first(sub {
my $match = shift;
$match->title('Revised title');
die "Instances of the same object should always be linked, consistent and up-to-date"
unless $article->title eq $match->title;
});
Product's homepage
Requirements:
· Perl