EntityModel
view release on metacpan or search on metacpan
lib/EntityModel.pod view on Meta::CPAN
=item * B<fields> - list of fields that are indexed
=back
The fields in an index can be defined as functions.
Constraints include attributes such as unique column values.
Models can also contain additional information as defined by plugins - see L<EntityModel::Plugin>
for more details on this.
=head1 USAGE
An entity model can be loaded from several sources. If you have a database definition:
create table test ( id int, name varchar(255), url text );
then loading the SQL plugin with the database name will create a single entity holding
two fields.
If you also load L<EntityModel::Plugin::Apply::Perl>, you can access this table as follows:
my $tbl = Entity::Test->create({ name => 'Test', url => '/there' })->commit;
my ($entity) = Entity::Test->find({ name => 'Test' });
is($orig->id, $entity->id, 'found same id');
=head1 IMPLEMENTATION
Nearly all classes use L<EntityModel::Class> to provide basic structure including accessors
and helper functions and methods. This also enables strict, warnings and Perl 5.10 features.
Logging is handled through L<EntityModel::Log>, which imports functions such as logDebug.
Arrays and hashes are typically wrapped using L<EntityModel::Array> and L<EntityModel::Hash>
respectively, similar in concept to L<autobox>.
For error handling, an L<EntityModel::Error> object is returned - this allows chained method
calling without having to wrap in eval or check the result of each step when you don't care
about failure. The last method in the chain will return false in boolean context.
=head1 OVERVIEW
The current L<EntityModel::Model> can be read from a number of sources:
=over 4
=item * L<EntityModel::Definition::XML> - XML structured definition holding the entities, fields and any additional
plugin-specific data. All information is held in the content - no attributes are used, allowing this format to be
interchangeable with JSON and internal Perl datastructures.
=item * L<EntityModel::Definition::JSON> - standard Javascript Object Notation format.
=item * L<EntityModel::Definition::Perl> - nested Perl datastructures, with the top level being a hashref. Note that
this is distinct from the Perl class/entity structure described later.
=back
Aside from entities, models can also contain plugin-specific information
such as site definition or database schema. It is also possible - but not
recommended - to store credentials such as database user and password.
Once a model definition has been loaded, it can be applied to one or more of the following:
=over 4
=item * L<EntityModel::Support::SQL> - database schema
=item * L<EntityModel::Support::Perl> - Perl classes
=item * L<EntityModel::Support::CPP> - C++ classes
=item * L<EntityModel::Support::JS> - Javascript code
=back
The SQL handling is provided as a generic DBI-compatible layer with additional support in subclasses
for specific databases. Again, Note that the L<EntityModel::Support::SQL> is intended for applying the
model to the database schema, rather than accessing the backend storage. The L<EntityModel::Support>
classes apply the model to the API, so in the case of the database this involves creating and updating
tables. For Perl, this dynamically creates a class structure in memory, and for C++ or JS this will
export the required support code for inclusion in other projects.
In terms of accessing backend storage, each of the language-specific support options provides an API
which can communicate with one or more backend storage implementations, rather than being tightly coupled
to a data storage method. Typically the Perl backend would interact directly with the database, and C++/JS
would use a REST API against a Perl server.
=head2 BACKEND STORAGE
Backend storage services are provided by subclasses of L<EntityModel::Storage>.
=over 4
=item * L<EntityModel::Storage::PostgreSQL> - PostgreSQL database support
=item * L<EntityModel::Storage::MySQL> - MySQL database support
=item * L<EntityModel::Storage::SQLite> - SQLite3 database support
=back
=head2 CACHING
Cache layers are handled by L<EntityModel::Cache> subclasses.
=over 4
=item * L<EntityModel::Cache::MemcachedFast> - memcached layer using L<Cache::Memcached::Fast>.
=item * L<EntityModel::Cache::Perl> - cache via Perl variables
=back
=head2 USAGE EXAMPLE
Given a simple JSON model definition:
{ entity : [
{ name : 'article', field : [
{ name : 'idarticle', type : 'bigserial' },
( run in 0.933 second using v1.01-cache-2.11-cpan-140bd7fdf52 )