NAME

DBIx::Class::Smooth::ResultBase - Short intro

VERSION

Version 0.0108, released 2020-11-29.

SYNOPSIS

    # in MyApp::Schema::Result::YourResultClass, instead of inheriting from DBIx::Class::Core
    use parent 'DBIx::Class::Smooth::Result::Base';

    column last_name => {
        data_type => 'varchar',
        size => 150,
        indexed => 1,
    };

DESCRIPTION

Adding indices (apart from primary keys and unique constraints) requires creating a sqlt_deploy_hook method and calling add_index manually. This module adds the indexed column attribute.

Possible values

indexed behaves differently depending on the value it is given:

  • If given a one-character value, that evaluates to true, an index is created named [table_name]_idxa_[column_name].

  • If given a more-than-one-character value an index is created named [table_name]_idxm_[index_name]. If multiple columns are given the same name a composite index is created.

  • If given an array reference each value in it is treated according to the two rules above.

With these column definitions:

    table('Author');
    column first_name => {
        data_type => 'varchar',
        size => 150,
        indexed => 'name',
    };
    column last_name => {
        data_type => 'varchar',
        size => 150,
        indexed => [1, 'name'],
    };
    column country => {
        data_type => 'varchar',
        size => 150,
        indexed => 1,
    };

The following indices are created:

  • Author_idxm_name for first_name and last_name

  • Author_idxa_last_name for last_name

  • Author_idxa_country for country

Still need a custom sqlt_deploy_hook?

If you need an sqlt_deploy_hook method in a result source just call the parent's sqlt_deploy_hook in your local sqlt_deploy_hook:

    sub sqlt_deploy_hook {
        my $self = shift;
        my $table = shift;

        $self->next::method($table);

        ...

    }

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.