NAME

Types::SQL::Util - extract DBIx::Class column_info from types

VERSION

version v0.4.1

SYNOPSIS

use Types::SQL -types;
use Types::Standard -types;

use Types::SQL::Util;

my $type = Maybe[ Varchar[64] ];

my %info = column_info_from_type( $type );

DESCRIPTION

This module provides a utility function that translates types into column information.

EXPORTS

column_info_from_type

my %info = column_info_from_type( $type );

This function returns a hash of column information for the add_column method of DBIx::Class::ResultSource, based on the type.

Besides the types from Types::SQL, it also supports the following types from Types::Standard, Types::Common::String, and Types::Common::Numeric:

ArrayRef

This treats the type as an array.

Bool

This is treated as a boolean type.

Enum

This is treated as an enum type, which can be used with DBIx::Class::InflateColumn::Object::Enum.

InstanceOf

For DateTime, DateTime::Tiny, Time::Moment and Time::Piece objects, this is treated as a datetime.

Int

This is treated as an integer without a precision.

Maybe

This treats the type in the parameter as nullable.

Num

This is treated as a numeric without a precision.

PositiveOrZeroInt

This is treated as an unsigned integer without a precision.

PositiveOrZeroNum

This is treated as an unsigned numeric without a precision.

SingleDigit

This is treated as an unsigned integer of size 1.

Str

This is treated as a text value without a size.

NonEmptyStr

LowerCaseStr

UpperCaseStr

These are treated the same as "Str". In the future, if DBIx::Class supports database-related constraints, this will be added to the metadata.

SimpleStr

This is treated as a text value with a size of 255.

NonEmptySimpleStr

LowerCaseSimpleStr

UpperCaseSimpleStr

These are treated the same as "SimpleStr". In the future, if DBIx::Class supports database-related constraints, this will be added to the metadata.

CUSTOM TYPES

You can declare custom types from these types and still extract column information from them:

use Type::Library
  -base,
  -declare => qw/ CustomStr /;

use Type::Utils qw/ -all /;
use Types::SQL -types;
use Types::SQL::Util;

declare CustomStr, as Varchar [64];

...

my $type = CustomStr;
my %info = column_info_from_type($type);

SEE ALSO

Types::SQL.

Types::Standard

SOURCE

The development version is on github at https://github.com/robrwo/Types-SQL and may be cloned from git://github.com/robrwo/Types-SQL.git

BUGS

Please report any bugs or feature requests on the bugtracker website https://github.com/robrwo/Types-SQL/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Robert Rothenberg <rrwo@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2016-2022 by Robert Rothenberg.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)