NAME
DBomb::Base::Defs - Table definition routines.
SYNOPSIS
package Customer;
use base qw(DBomb::Base);
Customer->def_data_source ('my_db', 'Customer');
Customer->def_accessor ('cust_id', { column => 'id', auto_increment => 1 });
Customer->def_column ('id', { accessor => 'id', auto_increment => 1 }); # Same thing!
Customer->def_accessor ('name'};
Customer->def_accessor ('address');
Customer->def_accessor ('affiliate_id');
Customer->def_accessor ('database_time', { expr => 'now()'} );
## Explicit key creation
Customer->def_primary_key ([qw(id cust_loc)]);
Customer->def_key ([qw(name affiliate_id)]);
## Relationship based on primary key
Customer->def_has_a ('affiliate', 'Affiliate', +{})
Customer->def_has_many ('orders', 'Order',+{})
## Relationship explicitly defined
Customer->def_has_a ('affiliate', [qw(name aff_id)], 'Affiliate_table', [qw(c_name id)]);
Customer->def_has_many ('orders', 'Order', ['cust_id'], ['id'],+{});
## Relationship based on a join
Employee->def_has_many ('supervisors', 'Supervisor',
new DBomb::Query->select('super_id')
->from('emp_super')
->join('employee')
->using('emp_id')
->where(+{emp_id => '?'}), sub { shift->emp_id });
## select multiple columns at once for speed
Customer->def_select_group ([qw(name address)]);
## name the select_group so you can refer to it later
Customer->def_select_group ('reports' => [qw(name affiliate)]);
CLASS METHODS
- def_accessor ( $accessor_name, \%options )
-
Customer->def_accessor( 'id', { column => 'cust_id', auto_increment => 1 } );
Options (explained below):
column => NAME auto_increment => BOOLEAN select_when_null => VALUE update_when_empty => VALUE select_trim => BOOLEAN update_trim => BOOLEAN string_mangle => BOOLEAN
- column => NAME
-
The column name in the database. The default is the accessor name.
- auto_increment => BOOLEAN
-
The column value is generated by the database, and should not be INSERTED.
- select_when_null => VALUE
-
Select VALUE when a column's value is NULL.
- update_when_empty => VALUE
-
Use VALUE instead of the empty string for updates and inserts.
- select_trim => BOOLEAN
-
Trim leading and trailing whitespace after selecting the value from the database.
- update_trim => BOOLEAN
-
Trim leading and trailing whitespace before updating or inserting.
- string_mangle => BOOLEAN
-
Apply all string mangling features to this column. This option is just a shortcut for:
{ select_trim => 1, update_trim => 1, select_when_null => '', update_when_empty => undef }