NAME
DBIx::Meld - An ORMish amalgamation.
SYNOPSIS
use DBIx::Meld;
my $meld = DBIx::Meld->new( $dsn, $user, $pass );
$meld->insert( 'users', {user_name => 'smith023'} );
my $rows = $meld->array_of_hash_rows( 'users', ['user_name', 'email'], {status => 1} );
foreach my $row (@$rows) {
print "$row->{user_name}: $row->{email}\n";
}
# or, in a more ORMish fashion:
my $users = $meld->resultset('users');
$users->insert({user_name => 'smith023'});
my $rows = $users->search({ status => 1 })->array_of_hash_rows(['user_name', 'email']);
DESCRIPTION
This module combines the features of DBIx::Connector, SQL::Abstract, and the various DateTime::Format modules, with some of the design concepts of DBIx::Class.
EXPERIMENTAL
This module is in a bit of an expirimental state. It hasn't yet been used in any large procjets, some bits still need automated tests, and the API may still be changing before this module can be called stable.
That being said, the majority of the features that this module provides will not be changing. In addition, this module is a light-weight wrapper around code that has been stable for years and has regular production use, so don't be too worried.
If you have a success story (or fail story) of using this module, or any other feedback, then please let the author know.
WHY
When writing raw DBI code there is a huge lacking of core features that other more advanced libraries provide, such as DBIx::Class. These missing features are:
Robust connection and transation handling.
Greatly reduced need to write raw SQL.
Database independent date and time handling.
Ability to progressively construct queries using resultsets.
So, the intent of this module is to fill this gap. With this module you are still dealing with low-level DBI calls, yet you still get many of these great benefits.
Even with this module you will often need to write raw DBI code, as DBIx::Meld isn't meant to be the one tool that rules them all. Instead, DBIx::Meld is meant to simplify the majority of the DBI work you do, but not all of it.
YAORM
This module is not "Yet Another ORM". The point of this module is that *it is not an ORM*. It is ORMish because it has some aspects that act similarly to the ORMs available to us today. But, that is as deep as it goes.
If you want an ORM, try out DBIx::Class. It is superb.
CONSTRUCTOR
There are several ways to create a new DBIx::Meld object. The most common way is to call it just like DBIx::Connector:
my $meld = DBIx::Meld->new( $dsn, $user, $pass, $attrs ); # $attrs is optional
Or you can do it using name/value pairs:
my $meld = DBIx::Meld->new( connector => [$dsn, $user, $pass] );
The connector attribute may also be an already blessed object:
my $connector = DBIx::Connector->new( $dsn, $user, $pass );
my $meld = DBIx::Meld->new( connector => $connector );
TRAITS
DBIxConnector
$meld->txn(sub{ ... });
# This does the same thing:
$meld->connector->txn(sub{ ... });
This traite provides all of DBIx::Connector's methods as methods on DBIx::Meld. Ready more at DBIx::Meld::Traits::DBIxConnector.
SQLAbstract
$meld->insert('users', {user_name => 'smith023'});
$meld->update('users', {email => 'joe@example.com'}, {user_id => 123});
$meld->delete('users', {status => 0});
# etc...
This trait provides access to most of SQL::Abstract's methods as methods on DBIx::Meld. Ready more at DBIx::Meld::Traits::SQLAbstract.
DateTimeFormat
my $format_class = $meld->datetime_formatter();
$meld->format_datetime( DateTime->now() );
$meld->format_date( DateTime->now() );
This trait provides access to the appropriate DateTime::Format module and provides helper methods on DBIx::Meld. Read more at DBIx::Meld::Traits::DateTimeFormat.
ResultSet
my $user = $meld->resultset('users');
This trait provides the resultset() method which, when given a table name, returns an DBIx::Meld::ResultSet object. Read more at DBIx::Meld::Traits::ResultSet.
TODO
Support GROUP BY, HAVING, and LIMIT (and Data::Page?) clauses.
Integrate DBIC's well-tested auto-generated ID retrieval code. This can be tricky since each DB does it in a different way (/looks at Oracle). Then, insert() can return that ID.
Support pluggable traits so that other CPAN authors can release distros that easly plug in and add functionality.
Add an update_sth() method to the SQLAbstract trait. This is difficult since it appears that SQL::Abstract->values() only works with selects, inserts, and deletes.
Verify how DBI errors are propogated back to the user so that the error is useful and points to the area of code that best helps the user understand and fix the issue.
AUTHOR
Aran Clary Deltac <bluefeet@gmail.com>
LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.