Types::SQL::Util - extract DBIx::Class column_info from types
version v0.7.0
use Types::SQL -types; use Types::Standard -types; use Types::SQL::Util; my $type = Maybe[ Varchar[64] ]; my %info = column_info_from_type( $type );
This module provides a utility function that translates types into column information.
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.
add_column
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.
boolean
DateTime
From Types::DateTime. This is a timestamp.
timestamp
DateTimeUTC
DateTimeWithZone
From Types::DateTime. These are timestamp with time zone.
timestamp with time zone
Enum
This is treated as an enum type, which can be used with DBIx::Class::InflateColumn::Object::Enum.
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.
uuid
Int
This is treated as an integer without a precision.
integer
Maybe
This treats the type in the parameter as nullable.
Num
This is treated as a numeric without a precision.
numeric
PositiveOrZeroInt
This is treated as an unsigned integer without a precision.
unsigned integer
PositiveOrZeroNum
This is treated as an unsigned numeric without a precision.
unsigned numeric
SingleDigit
This is treated as an unsigned integer of size 1.
Str
This is treated as a text value without a size.
text
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.
current_timestamp
Uuid
From Types::UUID. This is a uuid.
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);
Types::SQL.
Types::Standard
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
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.
Robert Rothenberg <rrwo@cpan.org>
This software is Copyright (c) 2016-2023 by Robert Rothenberg.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
To install Types::SQL, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Types::SQL
CPAN shell
perl -MCPAN -e shell install Types::SQL
For more information on module installation, please visit the detailed CPAN module installation guide.