NAME

CXC::DB::DDL::Util

VERSION

version 0.13

DESCRIPTION

CXC::DB::DDL::Util provides generators to ease creation of, amongst, others, CXC::DB::DDL::FIELD objects. It uses Exporter::Tiny as its base exporter, allowing renaming of exported symbols and other things.

SUBROUTINES

SQL_TYPE_NAMES

@typenames = SQL_TYPE_NAMES;

returns all of the DBI supported types (without the SQL_ prefix)

TYPENAME

TYPENAME is one of the SQL types recognized by DBI. See "sql_type_constants" in CXC::DB::DDL::Util for more information.

Called as, e.g.

INTEGER( %attr )

these are generators which return subroutines with the following signature:

sub ( $field_name )

which return a CXC::DB::DDL::Field object with the specified SQL datatype (in this example INTEGER), field name ($field_name) and attributes (%attr).

These are available for individual export or in entirety via the type_funcs tag.

They are typically used in conjunction with the "xFIELDS" subroutine, e.g.

xFIELDS(
    segment        => INTEGER,
    obsid          => INTEGER( is_primary_key => 1 ),
    target_type    => VARCHAR( is_nullable => 1 ),
)

"xFIELDS" essentially turns this into:

fields => [
    INTEGER('segment'),
    INTEGER( 'obsid', is_primary_key => 1 ),
    VARCHAR( 'target_type' is_nullable => 1 ),
]

which is more painful to write and look at.

xTYPE

xTYPE ( $type, %attr )

A generic form of e.g., "INTEGER". Type is a numeric DATA_TYPE from $DBI::EXPORT_TAGS{sql_types};

xFIELDS

@field_spec = xFIELDS( array of  Tuple[ NonEmptyStr, CodeRef ] );

returns a list of

fields => \@spec,

where @spec generated by running

CodeRef->(NonEmptyStr)

for each tuple.

xCHECK

$string = xCHECK( $field, @values )

generates a check constraint as a string which looks like

$field in ( $value[0], $value[1], ...  )

sqlt_producer_map

$sqlt_producer = sqlt_producer_map( $dbd );

Map $dbd (typically from $dbh-{Driver}{NAME}>) to what SQL::Translator wants. Actually, this just checks for known (to me) deviations; everything else is returned as.

SYNTAX

use CXC::DB::DDL::Util -all;

# import xFIELDS, xCHECK, xTYPE
use CXC::DB::DDL::Util -schema_funcs;

# import type function generators (e.g. INTEGER, DOUBLE )
use CXC::DB::DDL::Util -type_funcs;

# import type function generators (e.g. INTEGER, DOUBLE )
use CXC::DB::DDL::Util { prefix => 'SQL_' }, -type_funcs;

@CXC_DB_DDL_FIELD_objects = xFIELDS(
    segment        => INTEGER,
    obsid          => INTEGER( is_primary_key => 1 ),
    target_type    => VARCHAR( is_nullable => 1 ),
);

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