DBIx::EnumConstraints - generates enum-like SQL constraints.
use DBIx::EnumConstraints; my $ec = DBIx::EnumConstraints->new({ table => 'the_table' , name => 'kind', fields => [ [ 'a', 'b' ] , [ 'b' ] ] });
This module generates SQL statements for enforcing enum semantics on the database columns.
Enum columns is the column which can get one of 1 .. k values. For each of those values there are other columns which should or should not be null.
For example in the SYNOPSIS above, when kind column is 1 the row should have both of a and b columns not null. When kind column is 2 the row should have a but no b columns.
kind
a
b
$args should be HASH reference containing the following parameters:
$args
The table for which to generate the constraints.
The name of the enum.
Array of arrays describing columns dependent on the enum. Each row is index is the possible value of enum minus 1 (e.g. row number 1 is for enum value 2).
The items are column names. There is a possibility to mark optional columns by using trailing ? (e.g. b? denotes an optional b field.
?
b?
Hash of columns dependent on other columns. E.g. a => [ 'b', 'c' ] means that when a is present b, c columns should be present as well.
c
The key column should be given in fields parameter above.
fields
Runs $callback over registered enum states. For each state passes state index, fields which are in the state and fields which are out of the state.
$callback
The fields are passed as ARRAY references.
Generates suitable PostgreSQL constraints using the fields.
Also generates drop plpgsql function to automate dropping of the constraints.
Loads fields configuration from the database using current constraints.
Boris Sukholitko CPAN ID: BOSU boriss@gmail.com
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install DBIx::EnumConstraints, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::EnumConstraints
CPAN shell
perl -MCPAN -e shell install DBIx::EnumConstraints
For more information on module installation, please visit the detailed CPAN module installation guide.