NAME
CXC::DB::DDL::Table - A Table
VERSION
version 0.21
DESCRIPTION
CXC::DB::DDL::Table represents a database table, including its fields, indexes, and constraints.
OBJECT ATTRIBUTES
schema
The schema that the table is in.
name
The table name, qualified with its schema.
temporary
true if the table should be created as a temporary table
indexes
A list of table indexes, see the "indexes" constructor parameter for more information.
constraints
A list of table constraints, see the "constraints" constructor parameter for more information.
checks
DEPRECATED.
A list of table check constraints, see the "check" constructor parameter for more information.
fields
The list of fields as instances of the CXC::DB::DDL::Field class (or a subclass). See the "fields" constructor parameter.
CONSTRUCTORS
new
$table = CXC::DB::DDL::Table->new( %params );
%params
may have the following entries:
name
string-
The table name. If the name is qualified with a schema, e.g.
<schema-name>.<table-name>
The schema will be extracted for the "schema" parameter.
Note that if a separate schema is provided via the "schema" parameter, the table name is not parsed for a schema, so don't specify one or things will break.
schema
=> string-
An optional schema.
temporary
=> boolean-
True if the table should be created as a temporary table
indexes
=> arrayref-
An array of indexes; an index is a hashref; see "Index" in CXC::DB::DDL::Types for its structure.
constraints
-
One or more table constraints, as either a single constraint or as an array of constraints.
Constraints must meet the "Constraint" in CXC::DB::DDL::Types type.
If the constraint attribute expression is a coderef, it is called as
$expression->( $dbh, $sqlt, $constraint )
where $dbh is DBI handle, $sqlt is the SQL::Translator object, and must return a scalar containing the final expression. This is typically used to ensure that identifiers are properly quoted. See "quote" in DBI and "quote_identifier" in DBI.
$dbh, $sqlt and $constraint must not be changed.
checks
DEPRECATED-
Use a check constraint instead by adding an entry to "constraints" with fields
type => CHECK_C, expression => $expr
Originally: The list of table check constraints
fields
-
A list of field specifications. A specification is either:
- an instance of CXC::DB::DDL::Field or a subclass
- a hashref which can be passed to a field constructor.
-
The default class is CXC::CB::DDL::Field. To change the default, subclass this class, and override the "field_class" class method.
CLASS METHODS
field_class
returns the name of the class used by the constructor to create a field object from a hash field specification. Override this in a subclass to change it.
METHODS
has_schema
true if the "schema" attribute was set.
to_sqlt
$sqlt_table = $table->to_sqlt( $dbh, $schema );
Return a SQL::Translator::Schema::Table object for the table. Requires a DBI data base handle and an SQL::Translator::Schema object.
exists
$bool = $table->exists;
Check if the table exists in the database
field_names
\@field_names = $table->field_names;
return the names of all of the fields
clear
$table->clear;
clear the rows from the table
drop
$table->drop;
delete the table from the database
add_to_schema
$table->add_to_schema( $dbh, $schema );
Add the table to the schema (a SQL::Translator::Schema object).
SUBROUTINES
FIELD_CLASS
SUPPORT
Bugs
Please report any bugs or feature requests to bug-cxc-db-ddl@rt.cpan.org or through the web interface at: https://rt.cpan.org/Public/Dist/Display.html?Name=CXC-DB-DDL
Source
Source is available at
https://gitlab.com/djerius/cxc-db-ddl
and may be cloned from
https://gitlab.com/djerius/cxc-db-ddl.git
SEE ALSO
Please see those modules/websites for more information related to this module.
AUTHOR
Diab Jerius <djerius@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2022 by Smithsonian Astrophysical Observatory.
This is free software, licensed under:
The GNU General Public License, Version 3, June 2007