NAME

CXC::DB::DDL - DDL for table creation, based on SQL::Translator::Schema

VERSION

version 0.21

DESCRIPTION

CXC::DB::DDL provides a procedural interface to generating DDL to create and drop database tables.

It uses SQL::Translator to create the required SQL, and provides a little bit of extra DSL sauce in CXC::DB::DDL::Util.

See CXC::DB:DDL::Manual::Intro.

CONSTRUCTORS

new

$ddl = CXC::DB::DDL->new( tables => [ $table, $table, ... ] );
$ddl = CXC::DB::DDL->new( tables => $table );

$ddl = CXC::DB::DDL->new( { tables => $table } );
$ddl = CXC::DB::DDL->new( { tables => [ $table, $table, ... ] } );

$ddl = CXC::DB::DDL->new( $table );
$ddl = CXC::DB::DDL->new( [ $table, $table, ... ] );
w
Construct an object which manages a set of tables, their fields,
constraints, and indices.

There are too many ways of calling this routine.

A $table is either

CLASS METHODS

table_class

returns the name of the class used by the constructor to create a table object from a hash. Override this in a subclass to change it.

METHODS

table

# return CXC::DB::DDL::Table object for named table
$table = $ddl->table( $table_name );

# If only one table, return CXC::DB::DDL::Table object for it
$table = $ddl->table;

Returns undef if no matching table or no tables.

tables

\@tables = $ddl->tables

Return the tables.

add_table

$ddl->add_table( InstanceOf ['CXC::DB::DDL::Table'] );

sql

$ddl->sql( $dbh, %options )

Create the SQL associated with the $ddl object using the DBI database handle, $dbh. Various options may be specified:

create

One of the constants (see <CXC::DB::DDL::Constants>) CREATE_ONCE, CREATE_ALWAYS, CREATE_IF_NOT_EXISTS.

sqlt_comments boolean

Add comments in SQL [Default: true].

sqlt_quote_identifiers boolean

Quote identifiers (Default: producer specific)

sqlt_debug boolean

SQL::Translator constructor debug option.

sqlt_trace

SQL::Translator constructor trace option.

create

$ddl->create( $dbh, ?$create );

Create the tables associated with the $ddl object using the DBI database handle, $dbh.

$create is optional, and determines when the table is created. It can take one of the following constants (available from CXC::DB::DDL::Constants)

CREATE_ALWAYS

drops the tables and creates them.

CREATE_IF_NOT_EXISTS

checks if there are any missing tables; if not it returns.

CREATE_ONCE

will attempt to create the tables, and will throw an exception if one exists.

The default is CREATE_ONCE.

Returns true if tables were created.

clear

@not_cleared = $ddl->clear( $dbh );

Clear the contents of the tables in the DDL schema. DDL::Table objects for tables which do not exist are returned.

drop

$ddl->drop( $dbh );

Drop all of the tables in the DDL schema in reverse order of addition.

clone_simple

$cloned_ddl = $ddl->clone_simple

Return a new object based on the current one, running CXC::DB::DDL::Table::clone_simple on the tables.

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