PrePAN

Sign in to PrePAN

DBIx::Brev framework for laconic DBI powered by DBIx::Connection, Config::General, SQL::SplitStatement

Good

Synopsis

  perl -MDBIx::Brev=mydb -e"printf q{profit: %s\n},sql_value(q{select sum(amount) from Profit})"
  
  %car_price = map @$_, sql_query q{select id,price from Cars};
  
  sql_exec q{
    create table t1(a int primary key,b text);
    insert into t1 values(?,?);
    insert into t1 values(?,?);
    delete from t1;
    drop table t1;
  },1,2,3,4;

Description

DBIx::Brev provides framework for using DBI in more convenient & laconic way:

1) Establish connection using db aliases, setup in config file provided by Config::General (apache style)

2) Keep & reestablish connection automatically using DBIx::Connector facilities.

3) Using default connection paradigm to make DBI code laconic.

4) Switch easily & instantly between databases using cached connections

5) You can switch context by db_use($db_alias) or you can execute each of sql_xxx/inserts subroutines by specifiing explicit db alias as a first parameter without switching default database connection.

6) sql_exec executes multiple statements in single transaction using SQL::SplitStatement::split_with_placeholders to extract statements.

To make it work put to ~/dbi.conf or /etc/dbi.conf database aliases and switch easily between databases. It's suitable for one liners where less code is best approach. Also it will be good for everyone who likes laconic code.

Comments

Why not use the DBIx:: namespace?
Hi dolmen!
I agree it's better indeed and I followed this suggestion month ago.
Although I forgot to update description here.
Thank you for comment!

Please sign up to post a review.