my $model = EntityModel->new->load_from( JSON => \q({ "entity" : [ { "name" : "article", "field" : [ { "name" : "idarticle", "type" : "bigserial" }, { "name" : "title", "type" : "varchar" }, { "name" : "content", "type" : "text" } ], "primary" : { "field" : [ "idarticle" ], "separator" : ":" } ] }) )->apply('PostgreSQL' => { service => 'devserver' } )->apply('Perl' => { namespace => 'Entity' }); my $article = Entity::Article->create( title => 'Test article', content => 'Article content' ); my ($match) = Entity::Article->find( title => 'Test article' ); $match->title('Updated title');
Database abstraction across languages
EntityModel 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.
- Event-based approach - reads and writes are handled through callbacks, so the code can continue with other tasks while waiting for backend storage to respond
- Modify database schema without changing code - configuration is stored in formats such as JSON or XML allowing them to be changed without altering any of the core application code
- Access database tables from several different programming languages - the same configuration can be applied to multiple languages, generating the language-specific bindings automatically
- Dynamic code generation - some languages (Perl, Javascript) provide the ability to generate the class structure dynamically after loading the configuration, so no static code files are required
- Schema can be applied to a variety of database backends - switching between databases is typically a transparent process, involving only a single change to the schema loading step
- Graph-based editor - entities and relationships can be modified visually rather than having to edit the config file directly
- Support for caching - simple RAM cache, memcached and other caching models can be applied