The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

KiokuDB::Backend::DBI - DBI backend for KiokuDB

SYNOPSIS

    my $dir = KiokuDB->connect(
        "dbi:SQLite:dbname=foo",
        columns => [
            # specify extra columns for the 'entries' table
            # in the same format you pass to DBIC's add_columns

            name => {
                data_type => "varchar",
                is_nullable => 1, # probably important
            },
        ],
    );

    $dir->search({ name => "foo" }); # SQL::Abstract

DESCRIPTION

This backend for KiokuDB leverages existing DBI accessible databases.

The schema is based on two tables, entries and gin_index (the latter is only used if a Search::GIN extractor is specified).

The entries table has two main columns, id and data (currently in JSPON format, in the future the format will be pluggable), and additional user specified columns.

The user specified columns are extracted from inserted objects using a callback (or just copied for simple scalars), allowing SQL where clauses to be used for searching.

COLUMN EXTRACTIONS

The columns are specified using a DBIx::Class::ResultSource instance.

One additional column info parameter is used, extract, which is called as a method on the inserted object with the column name as the only argument. The return value from this callback will be used to populate the column.

If the column extractor is omitted then the column will contain a copy of the entry data key by the same name, if it is a plain scalar. Otherwise the column will be NULL.

These columns are only used for lookup purposes, only data is consulted when loading entries.

SUPPORTED DATABASES

This driver has been tested with MySQL 5 (4.1 should be the minimal supported version), SQLite 3, and PostgresSQL 8.3.

ATTRIBUTES

schema

Created automatically.

This is DBIx::Class::Schema object that is used for schema deployment, connectivity and transaction handling.

connect_info

An array reference whose contents are passed to "connect" in DBIx::Class::Schema.

If omitted will be created from the attrs dsn, user, password and dbi_attrs.

dsn
user
password
dbi_attrs

Convenience attrs for connecting using "connect" in KiokuDB.

User in connect_info's builder.

columns

Additional columns, see "COLUMN EXTRACTIONS".

serializer

KiokuDB::Serializer. Coerces from a string, too:

    KiokuDB->connect("dbi:...", serializer => "storable");

Defaults to KiokuDB::Serializer::JSON.

create

If true the existence of the tables will be checked for and the DB will be deployed if not.

Defaults to false.

extract

An optional Search::GIN::Extract used to create the gin_index entries.

Usually Search::GIN::Extract::Callback.

METHODS

See KiokuDB::Backend and the various roles for more info.

deploy

Calls "deploy" in DBIx::Class::Schema.

Deployment to MySQL requires that you specify something like:

    $dir->backend->deploy({ producer_args => { mysql_version => 4 } });

because MySQL versions before 4 did not have support for boolean types, and the schema emitted by SQL::Translator will not work with the queries used.

drop_tables

Drops the entries and gin_index tables.

VERSION CONTROL

http://github.com/nothingmuch/kiokudb-backend-dbi

AUTHOR

Yuval Kogman <nothingmuch@woobling.org>

COPYRIGHT

    Copyright (c) 2008 Yuval Kogman, Infinity Interactive. All rights
    reserved This program is free software; you can redistribute
    it and/or modify it under the same terms as Perl itself.