SQL::Entity - Entity sql abstraction layer.
SQL::Entity::Table | +----SQL::Entity
use SQL::Entity; my $entity = SQL::Entity->new( id => 'emp', name => 'emp', unique_expression => 'rowid', columns => { emp_name => sql_column(name => 'ename'), emp_no => sql_column(name => 'empno'), }, ); my($sql_text, $bind_variables) = $entity->query( sql_cond('emp_no', '>', '20') ->and(sql_cond('emp_name', 'NOT LIKE', 'HO%')) ) # select from database .... do some stuff my ($sql_text, $bind_variables) = $entity->insert( emp_no => '0', emp_name => 'Smith', ); # insert row/s ... do some stuff my ($sql_text, $bind_variables) = $entity->update( { ename => 'Smith'}, { empno => '20'} #pk values ); # update row ... do some stuff my ($sql_text, $bind_variables) = $entity->delete( empno => '20' ); # delete row/s ... do some stuff my $dept = SQL::Entity->new( name => 'dept', columns => [ sql_column(name => 'deptno'), sql_column(name => 'dname') ], ); my $emp = SQL::Entity->new( name => 'emp', primary_key => ['empno'], unique_expression => 'rowid', columns => [ sql_column(name => 'ename'), sql_column(name => 'empno'), sql_column(name => 'deptno') ], ); $emp->add_to_one_relationships(sql_relationship( target_entity => $dept, condition => sql_cond($dept->column('deptno'), '=', $entity->column('deptno')) # or join_columns => ['deptno'], )); $emp->add_subquery_columns($dept->column('dname'));
This class uses entity meta definition to generate different kinds of sql statmements.
sql_column sql_index sql_cond sql_and sql_or by 'all' tag
SQL fragment.
Expression that's value will be used to identifying the unique row in Entity. It may be any column or pseudo column like ROWID for Oracle, or expression like PK_COLUMN1||PK_COLUMN2
Association to the column object that based on unique_expression.
Association many_to_one, or one_to_one tables.
Association many_to_many, or one_to_many tables. To many relation implicitly creates to one relation on the reflective entity.
Allows use mini language variable,
SELECT t.* FROM (SELECT t.* FROM tab t WHERE t.col1 = [% var1 %]) t
Returns sql statement and bind variables, Takes optionally array ref of the requeted columns (undef returns all entity columns), condition object, bind_variables reference
my ($sql, $bind_variables) = $entity->query(undef, sql_cond('empno', '>', '20')->and(sql_cond('dname', 'NOT LIKE', 'HO%')) );
Returns sql that locks all rows that meets passed in condition It uses SELECT ... FOR UPDATE pattern. Takes optionally array ref of the requeted columns, condition object, bind_variables reference
my ($sql, $bind_variables) = $entity->lock(undef, sql_cond('empno', '>', '20')->and(sql_cond('dname', 'NOT LIKE', 'HO%')) );
Returns insert sql statement and bind variables
my ($sql, $bind_variables) = $entity->insert( dname => 'hr', deptno => '10', ename => 'adi', empno => '1', );
Returns update sql statement and bind variables
my ($sql, $bind_variables) = $entity->update( {dname => 'hr', deptno => '10', ename => 'adi', empno => '1',}, {the_rowid => 'AAAMgzAAEAAAAAgAAB'}, );
Returns deletes sql statement and bind variables
my ($sql, $bind_variables) = $entity->delete(empno => '1');
Returns condition that uniquely identify the entity. Takes the entity fields values, and validation flag. If validation flag is true, then exception will be raise if there are not condition values.
Retuns list of columns that can be selected. Takes requested columns as parameter.
Returns FROM .. sql fragment without join.
Returns FROM sql frgments with join clause.
Returns "JOIN ... " sql fragment for all to one relationship
Returns sql query + bind_variables to many relationship
Replaces all keys that are passed in as alias to column name
Return relationship object, takes relationship name.
All columns that belongs to this object.
Converts passed in argumets to condition object
Parses template variables.
Clones this entity
SQL::Entity::Table SQL::Entity::Index SQL::Entity::Column SQL::Entity::Condition
The SQL::Entity module is free software. You may distribute under the terms of either the GNU General Public License or the Artistic License, as specified in the Perl README file.
Adrian Witas, adrian@webapp.strefa.pl
See also DBIx::Connection DBIx::QueryCursor DBIx::PLSQLHandler.
1 POD Error
The following errors were encountered while parsing the POD:
=cut found outside a pod block. Skipping to next block.
To install SQL::Entity, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SQL::Entity
CPAN shell
perl -MCPAN -e shell install SQL::Entity
For more information on module installation, please visit the detailed CPAN module installation guide.