The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

version v0.1.3

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:

Bool

This is trated 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, 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.

Str

This is treated as a text value without a size.

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) 2017 by Robert Rothenberg.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)