DBIx::Class::Table - Basic table methods |
DBIx::Class::Table - Basic table methods
This class is responsible for defining and doing table-level operations on the DBIx::Class manpage classes.
__PACKAGE__->add_columns(qw/col1 col2 col3/);
Adds columns to the current class and creates accessors for them.
my @obj = $class->search_literal($literal_where_cond, @bind); my $cursor = $class->search_literal($literal_where_cond, @bind);
my $count = $class->count_literal($literal_where_cond);
my $count = $class->count({ foo => 3 });
my @obj = $class->search({ foo => 3 }); # "... WHERE foo = 3" my $cursor = $class->search({ foo => 3 });
To retrieve all rows, simply call search()
with no condition parameter,
my @all = $class->search(); # equivalent to search({})
If you need to pass in additional attributes (see Attributes in the DBIx::Class::ResultSet manpage for details) an empty hash indicates no condition,
my @all = $class->search({}, { cols => [qw/foo bar/] }); # "SELECT foo, bar FROM $class_table"
Identical to search except defaults to 'LIKE' instead of '=' in condition
__PACKAGE__->table('tbl_name'); Gets or sets the table name.
$class->find_or_create({ key => $val, ... });
Searches for a record matching the search condition; if it doesn't find one, creates one and returns that instead.
if ($obj->has_column($col)) { ... }
Returns 1 if the class has a column of this name, 0 otherwise.
=cut
sub has_column { my ($self, $column) = @_; return exists $self->_columns->{$column}; }
my $info = $obj->column_info($col);
Returns the column metadata hashref for a column.
=cut
sub column_info { my ($self, $column) = @_; die ``No such column $column'' unless exists $self->_columns->{$column}; return $self->_columns->{$column}; }
sub columns { die ``columns() is a read-only accessor, did you mean add_columns()?'' if (@_ > 1); return keys %{shift->_columns}; }
1;
Matt S. Trout <mst@shadowcatsystems.co.uk>
You may distribute this code under the same terms as Perl itself.
DBIx::Class::Table - Basic table methods |