Alzabo::Runtime::Table - Table objects
my $table = $schema->table('foo'); my $row = $table->row_by_pk( pk => 1 ); my $row_cursor = $table->rows_where( where => [ C<Alzabo::Column> object, '=', 5 } );
This object is able to create rows, either by making objects based on existing data or inserting new data to make new rows.
This object also implements a method of lazy column evaluation that can be used to save memory and database wear and tear, though it needs to be used carefully. Please see methods as well as "LAZY COLUMN LOADING" for details.
Alzabo::Table
Alzabo::Runtime::Row
Inserts the given values into the table. If no values are given for a primary key column and the column is sequenced then the values will be generated from the sequence.
values => $hashref
The hashref contains column names and values for the new row.
All other parameters given will be passed directly to the Alzabo::Runtime::Row->new method (such as the no_cache parameter).
Alzabo::Runtime::Row->new
no_cache
A new Alzabo::Runtime::Row object.
Alzabo::Exception::Params
The primary key can be either a simple scalar, as when the table has a single primary key, or a hash reference of column names to primary key values when the primary key is more than one column.
pk => $pk_val or \%pk_val
A new Alzabo::Runtime::Row object. If no rows in the database match the value(s) given then an empty list or undef will be returned (for list or scalar context).
This method is useful for regenerating a row that has been saved by reference to its id (returned by the Alzabo::Runtime::Row->id method). This may be more convenient than saving a multi-column primary key when trying to maintain state in a wbe app, for example.
Alzabo::Runtime::Row->id
row_id => $row_id
A string representation of a row's id (as returned by the Alzabo::Runtime::Row->id method).
Alzabo::Runtime::RowCursor
The following methods, rows_where and all_rows, all return an Alzabo::Runtime::RowCursor object representing the results of the query. This is the case even for queries that end up returning one or zero rows.
rows_where
all_rows
These three methods all take the following parameters in addition to whatever is described:
order_by => see below
This parameter can take one of three different things. The simplest form is to just give it a single column object. Alternatively, you can give it an array reference to a list of column objects. Finally you can give it a hash reference such as:
order_by => { columns => $column_object or \@column_objects, sort => 'ASC' or 'DESC' }
A simple way to retrieve a row cursor based on one or more colum values. This does not handle any conditionals besides equality.
where => [ Alzabo::Column object, $comparison, $value or Alzabo::Column object ]
Alzabo::Column
This parameter can take a variety of values. It can take a single array reference as shown above. The $comparison should be a string containing a SQL operator such as '>' or '='.
$comparison
'>'
'='
The parameter can also be an array of references to such arrays:
[ [ C<Alzabo::Column> object, $comparison, $value or C<Alzabo::Column> object ], [ C<Alzabo::Column> object, $comparison, $value or C<Alzabo::Column> object ] ]
For more details on exactly what the possibilities are here, please see the documentation for Alzabo::SQLMaker. Multiple values given to this parameter will be joined together by a logical 'AND'.
Given these items this method generates SQL that will retrieve a set of primary keys for the table.
An Alzabo::Runtime::RowCursor object representing the query.
Simply returns all the rows in the table.
All parameters given will be passed directly to the Alzabo::Runtime::Row->new method (such as the no_cache parameter).
A scalar indicating how many rows the table has.
func => $function
args => \@args
where => see rows_where method
This method is used to call arbitrary SQL functions such as 'AVG' or 'MAX'. If the function needs arguments, these can be passed in the args parameter. These may be either strings or Alzabo::Column objects. Either way, the arguments will be joined together by commas and placed in parentheses.
args
The value returned from the SQL function.
This concept was taken directly from Michael Schwern's Class::DBI module (credit where it is due).
By default, Alzabo::Runtime::Row objects only load data from the database as it is requested via the select method. This is stored internally in the object after being fetched. If the object is expired in the cache, it will erase this information and fetch it from the database again as needed.
This is good because it saves on memory and makes object creation quicker, but it is bad because you could potentially end up with one SQL call per column (excluding primary key columns, which are usually not fetched from the database).
This class provides two method to help you handle this potential problem. Basically these methods allow you to declare usage patterns for the table.
The first method, set_prefetch, allows you to specify a list of columns to be fetched immediately after object creation or after an object discovers it is expired in the cache. These should be columns that you expect to use extremely frequently.
set_prefetch
The second method, add_group, allows you to group columns together. If you attempt to fetch one of these columns, then all the columns in the group will be fetched. This is useful in cases where you don't often want certain data, but when you do you need several related pieces.
add_group
Given a list of column objects, this makes sure that all Alzabo::Runtime::Row objects fetch this data as soon as they are created, as well as immediately after they know they have been expired in the cache.
NOTE: It is pointless (though not an error) to give primary key column here as these are always prefetched (in a sense).
Given a list of Alzabo::Column objects, this method creates a group containing these columns. This means that if any column in the group is fetched from the database, then they will all be fetched. Otherwise column are always fetched singly. Currently, a column cannot be part of more than one group.
NOTE: It is pointless to include a column that was given to the set_prefetch method in a group here, as it always fetched as soon as possible.
This method primarily exists for use by the Alzabo::Runtime::Row class.
A list of column names (not objects) that should be prefetched.
A list of column names representing the group that this column is part of. If the column named is not part of a group, only the name passed in is returned.
Dave Rolsky, <autarch@urth.org>
To install Alzabo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Alzabo
CPAN shell
perl -MCPAN -e shell install Alzabo
For more information on module installation, please visit the detailed CPAN module installation guide.