| DBIx-DBO documentation | view source | Contained in the DBIx-DBO distribution. |
DBIx::DBO::Table - An OO interface to SQL queries and results. Encapsulates a table in an object.
# Create a Table object
my $table = $dbo->table('my_table');
# Get a column reference
my $column = $table ** 'employee_id';
# Quickly display my employee id
print $table->fetch_value('employee_id', name => 'Vernon');
# Find the IDs of fired employees
my @fired = @{ $table->fetch_column('id', status => 'fired');
# 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);
Table objects are mostly used for column references in a Query.
They can also be used for INSERTs, DELETEs and simple lookups (fetch_*).
newDBIx::DBO::Table->new($dbo, $table); DBIx::DBO::Table->new($dbo, [$schema, $table]); DBIx::DBO::Table->new($dbo, $table_object);
Create and return a new Table object.
Tables can be specified by their name or an arrayref of schema and table name or another Table object.
tablesReturn a list of Table objects, which will always be this Table object.
columnsReturn 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.
rowReturns a new Row object for this table.
fetch_row$table->fetch_row(%where);
Fetch the first matching row from the table returning it as a Row object.
The %where is a hash of field/value pairs. The value can be a SCALAR ref, which will be used without quoting.
$someone = $table->fetch_row(name => \'NOT NULL', age => 21, join_date => \'CURDATE()', end_date => undef);
fetch_value$table->fetch_value($column, %where);
Fetch the first matching row from the table returning the value in one column.
fetch_hash$table->fetch_hash(%where);
Fetch the first matching row from the table returning it as a hashref.
fetch_column$table->fetch_column($column, %where);
Fetch all matching rows from the table returning an arrayref of the values in one column.
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.
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.
These methods are accessible from all DBIx::DBO* objects.
dbhThe read-write DBI handle.
rdbhThe read-only DBI handle, or if there is no read-only connection, the read-write DBI handle.
do$table->do($statement) or die $table->dbh->errstr; $table->do($statement, \%attr) or die $table->dbh->errstr; $table->do($statement, \%attr, @bind_values) or die ...
This provides access to DBI->do method. It defaults to using 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.
| DBIx-DBO documentation | view source | Contained in the DBIx-DBO distribution. |