NAME
SQL::DB::Schema::Table - Perl representation of an SQL database table
SYNOPSIS
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;
#
DESCRIPTION
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.
DEFINITION KEYS
Key/value pairs can be set multiple times, for example when there is more than one index in the table.
schema => $schema
$schema must be a SQL::DB::Schema object. The internal reference to the schema is set to be weak.
table => $name
$name is the SQL name of the table.
class => $name
$name is the Perl class to be created for representing table rows.
bases => [$class1, $class2,...]
A list of classes that the class will inherit from.
columns => [ $col1, $col2, ... ]
$col1, $col2, ... are passed directly to SQL::DB::Schema::Column new().
primary => [ $name1, $name2, ... ]
$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.
unique => [ $name1, $name2, ... ]
$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.
index => $def
$def is an array reference of the following form. Note that not all databases accept all definitions.
[ columns => 'col1,col2', type => $type ]
foreign
For multiple foreign key definition. Not presently implemented.
type => $type
$type specifies the SQL table type. Applies only to PostgreSQL.
engine => $engine
$engine specifies the SQL backend engine. Applies only to MySQL.
default_charset => $charset
$charset specifies the SQL default character set. Applies only to MySQL.
tablespace => $tspace
$tspace specifies the PostgreSQL tablespace definition.
METHODS
new(@definition)
Returns a new SQL::DB::Schema::Table object. The @definition is a list of key/value pairs as defined under "DEFINITION KEYS".
name
Returns the SQL name of the database table.
class
Returns the name of the Perl class which can represent rows in the table.
columns
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.
column($name)
Returns the SQL::DB::Schema::Column object for the column $name.
column_names
Returns a list of the SQL names of the columns.
primary_columns
Returns the list of SQL::DB::Schema::Column objects which have been defined as primary.
primary_column_names
Returns the list of columns names which have been defined as primary.
schema
Returns the schema (a SQL::DB::Schema object) which this table is a part of.
sql
Returns the SQL statement for table creation.
sql_index
Returns the list of SQL statements for table index creation.
INTERNAL METHODS
These are used internally but are documented here for completeness.
add_primary
text2cols
SEE ALSO
SQL::DB::Schema, SQL::DB::Schema::Column, SQL::DB
AUTHOR
Mark Lawrence <nomad@null.net>
COPYRIGHT AND LICENSE
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.
NAME
SQL::DB::Schema::Table - description
SYNOPSIS
use SQL::DB::Schema::Table;
DESCRIPTION
SQL::DB::Schema::Table is ...
METHODS
new
setup_schema
setup_table
setup_class
setup_bases
setup_column
setup_columns
setup_primary
add_primary
setup_unique
setup_unique_index
setup_index
setup_foreign
setup_default_charset_mysql =head2 setup_default_charset_pg =head2 setup_engine_mysql =head2 setup_tablespace_pg =head2 setup_type_mysql
text2cols
name
class
columns
column_names
column_names_ordered
column
primary_columns
primary_column_names
arow
schema
set_db_type
db_type
sql_primary
sql_unique
sql_foreign
sql_default_charset_mysql =head2 sql_default_charset_pg =head2 sql_engine_mysql
sql_create_table
sql_create_indexes
sql_create
FILES
SEE ALSO
AUTHOR
Mark Lawrence <nomad@null.net>
COPYRIGHT AND LICENSE
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.