DBIx::EnumConstraintsDBIx::EnumConstraints is a Perl module that generates enum-like SQL constraints. | |
Download |
DBIx::EnumConstraints Ranking & Summary
Advertisement
- License:
- Perl Artistic License
- Price:
- FREE
- Publisher Name:
- Boris Sukholitko
- Publisher web site:
- http://search.cpan.org/~bosu/HTML-Tested-ClassDBI-0.19/lib/HTML/Tested/ClassDBI.pm
DBIx::EnumConstraints Tags
DBIx::EnumConstraints Description
DBIx::EnumConstraints is a Perl module that generates enum-like SQL constraints. DBIx::EnumConstraints is a Perl module that generates enum-like SQL constraints.SYNOPSIS use DBIx::EnumConstraints; my $ec = DBIx::EnumConstraints->new({ name => 'kind', fields => , ] }); # get enum field definition my $edef = $ec->enum_definition; # $edef is now 'kind smallint not null check (kind > 0 and kind < 2)' # get constraints array my @cons = $ec->constraints; # @cons is now ( # 'constraint k1_has_a check (kind 1 or a is not null)' # , 'constraint k1_has_b check (kind 1 or a is not null)' # , 'constraint k2_has_b check (kind 2 or b is not null)' # , 'constraint k2_has_no_a check (kind 2 or a is null)')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.CONSTRUCTORS$class->new($args)$args should be HASH reference containing the following parameters:nameThe name of the enum.fieldsArray of arrays describing fields 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).First item in the array is the state name. The rest of the items are field names. There is a possibility to mark optional fields by using trailing ? (e.g. b? denotes an optional b field.METHODS$self->enum_definitionReturns the definition of enum column. See SYNOPSIS for example.$self->for_each_kind($callback)Runs $callback over registered enum states. For each state passes state name, fields which are in the state and fields which are out of the state.The fields are passed as ARRAY references.$self->constraintsReturns the list of generated constraints. See SYNOPSIS above for an example. Requirements: · Perl
DBIx::EnumConstraints Related Software