The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Dezi::Stats::DBI - store Dezi statistics in a database

SYNOPSIS

 # see Dezi::Stats

DESCRIPTION

Dezi::Stats::DBI logs statistics to any backend supported by DBI. This class uses DBIx::Connector to manage a persistent DBI connection.

METHODS

init_store()

Sets up the internal database handle (accessible via conn() attribute).

conn

Returns the internal DBIx::Connector object.

table_name

Returns the table_name. Default is dezi_stats.

insert( hashref )

Writes hashref to the database.

schema

Callable as a function or class method. Returns string suitable for initializing a dezi_stats SQL table.

Example:

 perl -e 'use Dezi::Stats::DBI; print Dezi::Stats::DBI::schema' | sqlite3 dezi.index/stats.db

You can use SQL::Translator to initialize a non-SQLite database:

 my $dbh        = DBI->connect($dsn, $user, $pass);
 my $sql        = Dezi::Stats::DBI::schema();
 my $translator = SQL::Translator->new(
    show_warnings     => 1,
    validate          => 1,
    quote_identifiers => 1,
    no_comments       => 1,
 );
 my $mysql = $translator->translate(
    from       => 'SQLite',
    to         => 'MySQL',
    datasource => \$sql
 ) or die $translator->error;

 # Translator adds extra statements that do() can't handle.
 $mysql =~ s/^.*(CREATE TABLE .+?\));.*$/$1/s;

 $dbh->do($mysql);

AUTHOR

Peter Karman, <karman at cpan.org>

BUGS

Please report any bugs or feature requests to bug-dezi-stats at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Dezi-Stats. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc Dezi::Stats

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2012 Peter Karman.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.