DBIx::SQLEngine::Schema::Table - A table in a data source
$sqldb = DBIx::SQLEngine->new( ... ); $table = $sqldb->table( $table_name ); $hash_ary = $table->fetch_select( where => { status => 2 } ); $table->do_insert( values => { somefield => 'A Value', status => 3 } ); $table->do_update( values => { status => 3 }, where => { status => 2 } ); $table->do_delete( where => { somefield => 'A Value' } ); $hash = $table->fetch_row( $primary_key ); $table->insert_row( { somefield => 'Some Value' } ); $table->update_row( { id => $primary_key, somefield => 'Some Value' } ); $table->delete_row( { id => $primary_key } );
The DBIx::SQLEngine::Schema::Table class represents database tables accessible via a particular DBIx::SQLEngine.
By storing a reference to a SQLEngine and the name of a table to operate on, a Schema::Table object can facilitate generation of SQL queries that operate on the named table.
Each table can retrieve and cache a ColumnSet containing information about the name and type of the columns in the table. Column information is loaded from the storage as needed, but if you are creating a new table you must provide the definition.
The *_row() methods use this information about the table columns to facilitate common operations on table rows using their primary keys and simple hash-refs.
$sqldb->table( $tablename ) : $table
Convenience function to create a table with the given table name and sqlengine.
DBIx::SQLEngine::Schema::Table->new( sqlengine=>$sqldb, name=>$name ) : $table
Standard hash constructor. You are expected to provde the name and sqlengine arguments.
$table->name() : $string $table->name($string)
Get and set the table name. Required value. Identifies this table in the data source.
$table->get_name() : $string or exception
Returns the table name, or throws an exception if it is not set.
$table->sqlengine() : $sqldb $table->sqlengine($sqldb)
Get and set our current DBIx::SQLEngine. Required value. The SQLEngine provides the DBI connection and SQL execution capabilities required to talk to the remote data storage.
$table->get_sqlengine() : $sqldb or exception
Returns the SQLEngine, or throws an exception if it is not set.
$table->sqlengine_do( $method, %sql_clauses ) : $results or exception
Calls the provided method name on the associated SQLEngine, passing along the table name and the other provided arguments. Intended for methods with hash-based argument parsing like fetch_select( table => $table_name ).
fetch_select( table => $table_name )
$table->sqlengine_table_method( $method, @args ) : $results or exception
Calls the provided method name on the associated SQLEngine, passing along the table name and the other provided arguments. Intended for methods with list-based argument parsing like detect_table( $table_name ).
detect_table( $table_name )
$table->detect_sqlengine : $flag
Detects whether the SQL database is avaialable by attempting to connect.
$table->detect_table : @columns
Checks to see if the table exists in the SQL database by attempting to retrieve its columns.
$table->record_class() : $record_class
Returns the Record::Class which corresponds to the table.
$table->fetch_select ( %select_clauses ) : $row_hash_array
Calls the corresponding SQLEngine method with the table name and the provided arguments. Return rows from the table that match the provided criteria, and in the requested order, by executing a SQL select statement.
$table->visit_select ( $sub_ref, %select_clauses ) : @results $table->visit_select ( %select_clauses, $sub_ref ) : @results
Calls the provided subroutine on each matching row as it is retrieved. Returns the accumulated results of each subroutine call (in list context).
$table->select_row ( $primary_key_value ) : $row_hash $table->select_row ( \@compound_primary_key ) : $row_hash $table->select_row ( \%hash_with_primary_key_value ) : $row_hash
Fetches a single row by primary key.
$table->select_rows ( @primary_key_values_or_hashrefs ) : $row_hash_array
Fetches a set of one or more by primary key.
$table->fetch_one_value( %sql_clauses ) : $scalar
Calls fetch_select, then returns the first value from the first row of results.
$table->count_rows ( ) : $number $table->count_rows ( $criteria ) : $number
Return the number of rows in the table. If called with criteria, returns the number of matching rows.
$table->count_rows ( $colname, CRITERIA ) : $number
Returns the largest value in the named column.
$table->do_insert ( %insert_clauses ) : $row_count
Calls the corresponding SQLEngine method with the table name and the provided arguments.
$table->insert_row ( $row_hash ) : $row_count
Adds the provided row by executing a SQL insert statement. Uses column_names() and column_primary_is_sequence() to produce the proper clauses. Returns the total number of rows affected, which is typically 1.
$table->insert_rows ( @row_hashes ) : $row_count
Insert each of the rows from the provided list into the table. Returns the total number of rows affected, which is typically the same as the number of arguments passed.
$table->do_update ( %update_clauses ) : $row_count
$table->update_row ( $row_hash ) : $row_count
Update this existing row based on its primary key. Uses column_names() and column_primary_is_sequence() to produce the proper clauses. Returns the total number of rows affected, which is typically 1.
$table->update_rows ( @row_hashes ) : $row_count
Update several existing rows based on their primary keys. Uses update_row(). Returns the total number of rows affected, which is typically the same as the number of arguments passed.
$table->do_delete ( %delete_clauses ) : $row_count
$table->delete_row ( $row_hash_or_id ) : ()
Deletes the provided row from the table. Returns the total number of rows affected, which is typically 1.
$table->delete_rows ( @row_hashes_or_ids ) : ()
Deletes all of the provided rows from the table. Returns the total number of rows affected, which is typically the same as the number of arguments passed.
$table->columnset () : $columnset
Returns the current columnset, if any.
$table->get_columnset () : $columnset
Returns the current columnset, or runs a trivial query to detect the columns in the sqlengine. If the table doesn't exist, the columnset will be empty.
$table->columns () : @columns
Return the column objects from the current columnset.
$table->column_names () : @column_names
Return the names of the columns, in order.
$table->column_named ( $name ) : $column
Return the column info object for the specifically named column.
$table->table_exists() : $flag
Detects whether the table has been created and has not been dropped.
$table->create_table () $table->create_table ( $column_ary )
$table->drop_table ()
$table->ensure_table_exists ( $column_ary )
Create the table's remote storage if it does not already exist.
$table->recreate_table ()
Remove and then recreate the table's remote storage.
See DBIx::SQLEngine for the overall interface and developer documentation.
See DBIx::SQLEngine::Docs::ReadMe for general information about this distribution, including installation and license information.
To install DBIx::SQLEngine, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::SQLEngine
CPAN shell
perl -MCPAN -e shell install DBIx::SQLEngine
For more information on module installation, please visit the detailed CPAN module installation guide.