PrePAN

Sign in to PrePAN

Types::SQL Type library for SQL types, with ability to extract column info for DBIC

Author
robrwo@github
Date
URL
https://github.com/robrwo/Types-SQL
Status
In Review
Good

Synopsis

use Types::SQL qw/ Varchar /;
use Types::Standard -types;
use Types::SQL::Util;

my $type = Maybe [ Varchar [$size] ];
my %info = column_info_from_type($type);

# Info contains:
#
#  (     data_type   => 'varchar',
#        is_numeric  => 0,
#        size        => $size,
#        is_nullable => 1,
#  )

Description

I've been thinking that it would be nice when using DBIx::Class to be able to define columns using Type::Tiny-style types, e.g.

column foo => ( isa => Maybe[Varchar[12]] );

and have something that extracts the column info from the type.

Whether this should be a change to DBIC or a plugin/extension, I'm not yet sure. But the first thing is to create a type library and a utility function to extract the column_info from the type.

Part of the idea is that you can declare your own types that inherit from these types, and it should still work.

Comments

Please sign up to post a review.