NAME

Curio::Role::DBIx::Connector - Build Curio classes around DBIx::Connector. (DEPRECATED)

SYNOPSIS

Create a Curio class:

package MyApp::Service::DB;

use MyApp::Config;
use MyApp::Secrets;

use Curio role => '::DBIx::Connector';
use strictures 2;

key_argument 'connection_key';
export_function_name 'myapp_db';
always_export;
export_resource;

add_key 'writer';
add_key 'reader';

has connection_key => (
    is       => 'ro',
    required => 1,
);

sub dsn {
    my ($self) = @_;
    return myapp_config()->{db}->{ $self->connection_key() }->{dsn};
}

sub username {
    my ($self) = @_;
    return myapp_config()->{db}->{ $self->connection_key() }->{username};
}

sub password {
    my ($self) = @_;
    return myapp_secret( $self->connection_key() . '_' . $self->username() );
}

1;

Then use your new Curio class elsewhere:

use MyApp::Service::DB;

my $db = myapp_db('writer');

$db->run(sub{
    my ($one) = $_->selectrow_array( 'SELECT 1' );
});

DESCRIPTION

This role provides all the basics for building a Curio class which wraps around DBIx::Connector.

OPTIONAL ARGUMENTS

connector

Holds the DBIx::Connector object.

May be passed as either ain arrayref of arguments or a pre-created object. If this argument is not set then it will be built from "dsn", "username", "password", and "attributes".

REQUIRED METHODS

These methods must be implemented in your Curio class.

dsn

This method must return a DBI $dsn/$data_source, such as dbi:SQLite:dbname=:memory:.

OPTIONAL METHODS

These methods may be implemented in your Curio class.

username

If this method is not present then an empty string will be used for the username when the "connector" is built.

password

If this method is not present then an empty string will be used for the passord when the "connector" is built.

attributes

If this method is not present then an empty hashref will be used for the attributes when the "connector" is built.

sub attributes {
    return { SomeAttribute => 3 };
}

Note what "AUTOCOMMIT" says.

AUTOCOMMIT

The AutoCommit DBI attribute is defaulted to 1. You can override this in "attributes".

If the "connector" argument is set then this defaulting of AutoCommit is skipped.

FEATURES

This role turns on "does_caching" in Curio::Factory and sets "resource_method_name" in Curio::Factory to connector (as in "connector").

You can of course revert these changes:

does_caching 0;
resource_method_name undef;

SUPPORT

Please submit bugs and feature requests to the Curio-Role-DBIx-Connector GitHub issue tracker:

https://github.com/bluefeet/Curio-Role-DBIx-Connector/issues

ACKNOWLEDGEMENTS

Thanks to ZipRecruiter for encouraging their employees to contribute back to the open source ecosystem. Without their dedication to quality software development this distribution would not exist.

AUTHORS

Aran Clary Deltac <bluefeet@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2019 Aran Clary Deltac

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.