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

Build Status Coverage Status

NAME

Coteng - Lightweight Teng

SYNOPSIS

use Coteng;

my $coteng = Coteng->new({
    connect_info => {
        db_master => {
            dsn     => 'dbi:mysql:dbname=server;host=dbmasterhost',
            user    => 'nobody',
            passwd  => 'nobody',
        },
        db_slave => {
            dsn     => 'dbi:mysql:dbname=server;host=dbslavehost',
            user    => 'nobody',
            passwd  => 'nobody',
        },
    },
});

# or

my $coteng = Coteng->new({
    connect_info => {
        db_master => [
            'dbi:mysql:dbname=server;host=dbmasterhost', 'nobody', 'nobody', {
                PrintError => 0,
            }
        ],
        db_slave => [
            'dbi:mysql:dbname=server;host=dbslavehost', 'nobody', 'nobody',
        ],
    },
});

# or

use Coteng::DBI;

my $dbh1 = Coteng::DBI->connect('dbi:mysql:dbname=server;host=dbmasterhost', 'nobody', 'npbody');
my $dbh2 = Coteng::DBI->connect('dbi:mysql:dbname=server;host=dbslavehost', 'nobody', 'npbody');

my $coteng = Coteng->new({
    dbh => {
        db_master   => $dbh1,
        db_slave    => $dbh2,
    },
});


my $inserted_host = $coteng->db('db_master')->insert(host => {
    name    => 'host001',
    ipv4    => '10.0.0.1',
    status  => 'standby',
}, "Your::Model::Host");
my $last_insert_id = $coteng->db('db_master')->fast_insert(host => {
    name    => 'host001',
    ipv4    => '10.0.0.1',
    status  => 'standby',
});
my $host = $coteng->db('db_slave')->single(host => {
    name => 'host001',
}, "Your::Model::Host");
my $hosts = $coteng->db('db_slave')->search(host => {
    name => 'host001',
}, "Your::Model::Host");

my $updated_row_count = $coteng->db('db_master')->update(host => {
    status => "working",
}, {
    id => 10,
});
my $deleted_row_count = $coteng->db('db_master')->delete(host => {
    id => 10,
});

## no blessed return value

my $hosts = $coteng->db('db_slave')->single(host => {
    name => 'host001',
});

# Raw SQL interface

my $host = $coteng->db('db_slave')->single_named(q[
    SELECT * FROM host where name = :name LIMIT 1
], { name => "host001" }, "Your::Model::Host");
my $host = $coteng->db('db_slave')->single_by_sql(q[
    SELECT * FROM host where name = ? LIMIT 1
], [ "host001" ], "Your::Model::Host");

my $hosts = $coteng->db('db_slave')->search_named(q[
    SELECT * FROM host where status = :status
], { status => "working" }, "Your::Model::Host");
my $hosts = $coteng->db('db_slave')->search_named(q[
    SELECT * FROM host where status = ?
], [ "working" ], "Your::Model::Host");


package Your::Model::Host;

use Class::Accessor::Lite(
    rw => [qw(
        id
        name
        ipv4
        status
    )],
    new => 1,
);

DESCRIPTION

Coteng is a lightweight Teng, just as very simple DBI wrapper. Teng is a simple and good designed ORMapper, but it has a little complicated functions such as the row class, iterator class, the schema definition class (Teng::Row, Teng::Iterator and Teng::Schema). Coteng doesn't have such functions and only has very similar Teng SQL interface.

Coteng itself has no transaction and last_insert_id implementation, but has thir interface thanks to DBIx::Sunny. (Coteng uses DBIx::Sunny as a base DB handler.)

METHODS

Coteng provides a number of methods to all your classes,

NOTE

SEE ALSO

LICENSE

Copyright (C) y_uuki.

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

AUTHOR

y_uuki yuki.tsubo@gmail.com

POD ERRORS

Hey! The above document had some coding errors, which are explained below: