The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DBIx::Custom::Model - Model (experimental)

SYNOPSIS

use DBIx::Custom::Table;

my $table = DBIx::Custom::Model->new(table => 'books');

ATTRIBUTES

columns

    my $columns = $model->columns;
    $model      = $model->columns(['id', 'number']);

dbi

    my $dbi = $model->dbi;
    $model  = $model->dbi($dbi);

DBIx::Custom object.

filter

    my $dbi = $model->filter
    $model  = $model->filter({out => 'tp_to_date', in => 'date_to_tp'});

This filter is applied when DBIx::Custom include_model() is called.

name

    my $name = $model->name;
    $model   = $model->name('book');

Model name.

table

    my $table = $model->table;
    $model    = $model->table('book');

Table name. Model name and table name is different. Table name is real table name in database.

primary_key

    my $primary_key = $model->primary_key;
    $model          = $model->primary_key(['id', 'number']);

Foreign key. This is used by insert_at,update_at(), delete_at(),select_at().

METHODS

DBIx::Custom inherits all methods from Object::Simple, and you can use all methods of the object set to dbi. and implements the following new ones.

column_clause()

To create column clause automatically, use column_clause(). Valude of table and columns is used.

    my $column_clause = $model->column_clause;

If table is 'book'�Acolumn is ['id', 'name'], the following clause is created.

    book.id as id, book.name as name

These column name is for removing column name ambiguities.

If you remove some columns, use remove option.

    my $column_clause = $model->column_clause(remove => ['id']);

If you add some column, use add option.

    my $column_clause = $model->column_clause(add => ['company.id as company__id']);

delete

    $table->delete(...);
    

Same as delete() of DBIx::Custom except that you don't have to specify table option.

delete_all

    $table->delete_all(...);
    

Same as delete_all() of DBIx::Custom except that you don't have to specify table option.

delete_at

    $table->delete_at(...);
    

Same as delete() of DBIx::Custom except that you don't have to specify table and primary_key option.

method

    $table->method(
        count => sub {
            my $self = shift;
        
            return $self->select(column => 'count(*)', @_)
                        ->fetch_first->[0];
        }
    );
    

Add method to a DBIx::Custom::Table object.

insert

    $table->insert(...);
    

Same as insert() of DBIx::Custom except that you don't have to specify table option.

insert

    $table->insert_at(...);
    

Same as insert_at() of DBIx::Custom except that you don't have to specify table and primary_key option.

new

    my $table = DBIx::Custom::Table->new;

Create a DBIx::Custom::Table object.

select

    $table->select(...);
    

Same as select() of DBIx::Custom except that you don't have to specify table option.

select_at

    $table->select_at(...);
    

Same as select_at() of DBIx::Custom except that you don't have to specify table and primary_key option.

update

    $table->update(...);
    

Same as update() of DBIx::Custom except that you don't have to specify table option.

update_all

    $table->update_all(param => \%param);
    

Same as update_all() of DBIx::Custom except that you don't have to specify table name.

update_at

    $table->update_at(...);
    

Same as update_at() of DBIx::Custom except that you don't have to specify table and primary_key option.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 226:

Non-ASCII character seen before =encoding in ''book'�AC<column>'. Assuming CP1252