The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

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

VERSION

version v0.7.0

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.

Unless noted, these come from Types::Standard, Types::Common::String or Types::Common::Numeric.

ArrayRef

This treats the type as an array.

Bool

This is treated as a boolean type.

DateTime

From Types::DateTime. This is a timestamp.

DateTimeUTC

DateTimeWithZone

From Types::DateTime. These are timestamp with time zone.

Enum

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

InstanceOf

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

If you want a timestamp with a time zone, use Types::DateTime DateTimeWithZone or DateTimeUTC type.

Data::UUID or Data::GUID will be treated as uuid.

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.

Now

From Types::DateTime. This is a timestamp with a default set to the SQL current_timestamp function.

Uuid

From Types::UUID. This is a uuid.

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

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)