NAME

DBIx::DBO::Table - An OO interface to SQL queries and results. Encapsulates a table in an object.

SYNOPSIS

# Create a Table object
my $table = $dbo->table('my_table');

# Get a column reference
my $column = $table ** 'employee_id';

# Insert a new row into the table
$table->insert(employee_id => 007, name => 'James Bond');

# Remove rows from the table where the name IS NULL
$table->delete(name => undef);

DESCRIPTION

Table objects are mostly used for column references in a Query. They can also be used for INSERTs and DELETEs.

METHODS

new

DBIx::DBO::Table->new($dbo, $table);
# or
$dbo->table($table);

Create and return a new Table object. The $table argument that specifies the table can be a string containing the table name, 'customers' or 'history.log', it can be an arrayref of schema and table name ['history', 'log'] or as another Table object to clone.

tables

Return a list of Table objects, which will always be this Table object.

name

$table_name = $table->name;
($schema_name, $table_name) = $table->name;

In scalar context it returns the name of the table in list context the schema and table names are returned.

columns

Return a list of column names.

column

$table->column($column_name);
$table ** $column_name;

Returns a reference to a column for use with other methods. The ** method is a shortcut for the column method.

insert

$table->insert(name => 'Richard', age => 103);

Insert a row into the table. Returns true on success or undef on failure.

On supporting databases you may also use $table->last_insert_id to retreive the autogenerated ID (if there was one) from the last inserted row.

last_insert_id

$table->insert(name => 'Quentin');
my $row_id = $table->last_insert_id;

Retreive the autogenerated ID (if there was one) from the last inserted row.

Returns the ID or undef if it's unavailable.

bulk_insert

$table->bulk_insert(
    columns => [qw(id name age)], # Optional
    rows => [{name => 'Richard', age => 103}, ...]
);
$table->bulk_insert(
    columns => [qw(id name age)], # Optional
    rows => [[ undef, 'Richard', 103 ], ...]
);

Insert multiple rows into the table. Returns the number of rows inserted or undef on failure.

The columns need not be passed in, and will default to all the columns in the table.

On supporting databases you may also use $table->last_insert_id to retreive the autogenerated ID (if there was one) from the last inserted row.

delete

$table->delete(name => 'Richard', age => 103);

Delete all rows from the table matching the criteria. Returns the number of rows deleted or undef on failure.

truncate

$table->truncate;

Truncate the table. Returns true on success or undef on failure.

Common Methods

These methods are accessible from all DBIx::DBO* objects.

dbo

The DBO object.

dbh

The read-write DBI handle.

rdbh

The read-only DBI handle, or if there is no read-only connection, the read-write DBI handle.

config

$table_setting = $table->config($option);
$table->config($option => $table_setting);

Get or set the Table config settings. When setting an option, the previous value is returned. When getting an option's value, if the value is undefined, the DBIx::DBO's value is returned.

See "Available config options" in DBIx::DBO.

SEE ALSO

DBIx::DBO