NAME

Bot::Backbone::Service::Role::Storage - Helper for adding storage to standard modules

VERSION

version 0.161950

SYNOPSIS

    package MyBot::Service::Thing;
    use Bot::Backbone::Service;

    with qw(
        Bot::Backbone::Service::Role::Service
        Bot::Backbone::Service::Role::Responder
        Bot::Backbone::Service::Role::Storage
    );

    sub load_schema {
        my ($self, $conn) = @_;

        $conn->run(fixup => sub {
            $_->do(q[
                CREATE TABLE IF NOT EXISTS things(
                    name varchar(255),
                    PRIMARY KEY (name)
                )
            ]);
        });
    }

    # More bot service stuff...

DESCRIPTION

Uses DBIx::Connector to deliver a database handle to a bot service. It provides attributes for configuration the DBI DSN, username, and password and automatically manages the connection to the database using DBIx::Connector.

It also provides a sort of callback for loading the schema, which happens when the connection is first used.

ATTRIBUTES

db_dsn

This is the DSN to use when connecting to DBI. See your favorite DBD driver for details.

db_user

This is the username to use to connect.

db_password

This is the password to use when connecting.

db_conn

Use this to get at the DBIx::Connector object used to connect to your database.

REQUIRED METHODS

load_schema

    $service->load_schema($db_conn);

This is called to create the schema for your database. It is passed a reference to the newly created DBIx::Connector object. You should use it to run any DDL statements required to setup your schema. It does nothing to help you handle different flavors of SQL so if you need to do that, the way you do that is completely up to you.

DO NOT try to call "db_conn" on the invocant or your bot will lock up, just use the one passed in.

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by Qubling Software LLC.

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