
SQL::DB::Schema::Table - Perl representation of an SQL database table

use SQL::DB::Schema::Table;
my $table = SQL::DB::Schema::Table->new(
table => 'users',
class => 'User',
columns => [
[name => 'id', type => 'INT', primary => 1],
[name => 'name',type => 'VARCHAR(255)', unique => 1],
],
index => [
columns => 'name',
type => 'BTREE',
],
);
print $table->sql;
#

SQL::DB::Schema::Table objects represent SQL database tables. Once defined, a SQL::DB::Schema::Table object can be queried for information about the table such as the primary keys, name and type of the columns, and the SQL table creation syntax.

Key/value pairs can be set multiple times, for example when there is more than one index in the table.
$schema must be a SQL::DB::Schema object. The internal reference to the schema is set to be weak.
$name is the SQL name of the table.
$name is the Perl class to be created for representing table rows.
A list of classes that the class will inherit from.
$col1, $col2, ... are passed directly to SQL::DB::Schema::Column new().
$name1, $name2, ... are the columns names which are primary. Should only be used if the table has a multiple-column primary key. If the table has only a single primary key then that should be set in the column definition.
$name1, $name2, ... are columns names which must be unique. Should only be used if the table has a multiple-column unique requirements, Note that column definitions can also include unique requirements. This key can be defined more than once with a culmative result.
$def is an array reference of the following form. Note that not all databases accept all definitions.
[ columns => 'col1,col2', type => $type ]
For multiple foreign key definition. Not presently implemented.
$type specifies the SQL table type. Applies only to PostgreSQL.
$engine specifies the SQL backend engine. Applies only to MySQL.
$charset specifies the SQL default character set. Applies only to MySQL.
$tspace specifies the PostgreSQL tablespace definition.
This is the place to put trigger statements. In fact, any kind of SQL that needs to run after table create can be specified here. The hashref keys are the DBD type, so you can specify different code for different database systems.

Returns a new SQL::DB::Schema::Table object. The @definition is a list of key/value pairs as defined under "DEFINITION KEYS".
Returns the SQL name of the database table.
Returns the name of the Perl class which can represent rows in the table.
Returns the list of SQL::DB::Schema::Column objects representing each column definition in the database. The order is the same as they were defined.
Returns the SQL::DB::Schema::Column object for the column $name.
Returns a list of the SQL names of the columns.
Returns the list of SQL::DB::Schema::Column objects which have been defined as primary.
Returns the list of columns names which have been defined as primary.
Returns the list of SQL::DB::Schema::Table objects which have foreign keys pointing to this table. Takes a single optional SQL::DB::Schema::Table argument to add to the list.
Returns the schema (a SQL::DB::Schema object) which this table is a part of.
Returns the SQL statement for table creation.
Returns the list of SQL statements for table index creation.
Returns the SQL statements specified by the 'trigger' calls.

These are used internally but are documented here for completeness.

SQL::DB::Schema, SQL::DB::Schema::Column, SQL::DB

Mark Lawrence <nomad@null.net>

Copyright (C) 2007,2008 Mark Lawrence <nomad@null.net>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

SQL::DB::Schema::Table - description

use SQL::DB::Schema::Table;

SQL::DB::Schema::Table is ...




Mark Lawrence <nomad@null.net>

Copyright (C) 2007,2008 Mark Lawrence <nomad@null.net>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.