The Perl Advent Calendar needs more articles for 2022. Submit your idea today!

NAME

DBIx::Class::Smooth::Fields - Specify columns

VERSION

Version 0.0108, released 2020-11-29.

SYNOPSIS

    package Your::Schema::Result::Book;

    use Your::Schema::Result -components => [qw//];
    use DBIx::Class::Smooth::Fields -all;

    primary id => IntegerField(auto_increment => true);
    belongs Publisher => ForeignKey();
        col isbn => VarcharField(size => 13);
        col title => VarcharField(size => 150);
        col published_date => DateField();
        col language => EnumField(indexed => 1, -list => [qw/english french german spanish/]);

DESCRIPTION

DBIx::Class::Smooth::Fields defines an alternative way to specify columns in DBIx::Class result sources. They make most sense when used together with the functions exported by Smooth::Helper::Row::Creation.

These are just functions that return the hashes that you normally use to configure DBIx::Class columns. With a couple of exceptions, they only set data_type and is_numeric.

Any key-value pairs passed will be included in the returned hash. If you need to use other data types, you can use NumericalField or NonNumericalField which only sets is_numeric to the expected value.

Relational fields

ForeignKey()

    belongs Publisher => ForeignKey();

This is not a field type at all, but helps define the relationship with another result source. The heavy lifting is done by belongs, but in short there will be a field named publisher_id with the size and data_type of the id field in ::Publisher.

Numerical fields

These will all have is_numeric set to 1, in addition to their respective data_type:

    BitField         bit
    TinyIntField     tinyint
    SmallIntField    smallint
    MediumIntField   mediumint
    IntegerField     integer
    BigIntField      bigint
    SerialField      serial
    BooleanField     boolean
    DecimalField     decimal
    FloatField       float
    DoubleField      double

Non-numerical fields

These will all have is_numeric set to 0, in addition to their respective data_type:

    VarcharField     varchar
    CharField        char
    VarbinaryField   varbinary
    BinaryField      binary
    TinyTextField    tinytext
    TextField        text
    MediumTextField  mediumtext
    LongTextField    longtext
    TinyBlobField    tinyblob
    BlobField        blob
    MediumBlobField  mediumblob
    LongBlobField    longblod
    EnumField        enum
    DateField        date
    DateTimeField    datetime
    TimestampField   timestamp
    TimeField        time
    YearField        year

For EnumField, you can do EnumField(-list = [qw/one to three/])> instead of EnumField(extra = { list => [qw/one two three/] })>.

SEE ALSO

SOURCE

https://github.com/Csson/p5-DBIx-Class-Smooth

HOMEPAGE

https://metacpan.org/release/DBIx-Class-Smooth

AUTHOR

Erik Carlsson <info@code301.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2018 by Erik Carlsson.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.