[Koha-devel] Class::DBI vs DBIx::Class

Rick Welykochy rick at praxis.com.au
Fri Nov 7 20:41:58 CET 2008


Andrew Moore wrote:

> * DBIx::Class is being actively maintained. Class::DBI last had a
> release about 2 years ago, and from what I can tell no more releases
> are planned.
> * DBIx::Class supports JOINs between database tables.
> * DBIx::Class supports "inflating" or instantiating certain data
> fields into objects. So for example if you have a datetime field in
> your database, it can return you a DateTime object for that field, or
> it can return a Business::ISBN object for all ISBN fields.

Agreed. From what I have read, DBIx::Class seems to be the go.

I am certainly interested in pursuing the option of the package
creating a data model object, i.e. Business::ISBN, that contains
all attributes (columns) of a row from the table.

As well, the power of doing joins automatically cannot be underestimated.

Finally, if "inflating" implies that you can quickly load data
from without populating every attribute unless you really want
to is very useful. In Class::DBI one could specify which columns
are required on the initial load (for speed) and which are to be loaded
later if eventually required.


> Thanks again for looking over this code. I'm interested in hearing
> more from you since I think it's important we get this right. It would
> be foolish for me to think that my first proposal would necessarily be
> the "best" one.

When time permits I would like to get into the code you've written
as review how cleanly it can be written. I often think of things in
the clean style of Python these days. If the Perl code can "look nice"
and DWIM, then we are on the right track. If the solution we come up
with is clunky and difficult to use, then I think we've failed.

I good starting point is to write a tutorial for what you want to
accomplish. Here is a really simple and contrived example that
probably doesn't exactly match up with what DBIx::Class can do (yet),
but should get the point across:

----------------------------------------------------------------------

# load and manipulate item types in Koha 3

use C4::Datad:ItemType;  # encapsulation of all things regarding item types

# select

my $bookitemtype = C4::Data::ItemType->select('BK');  # select one by primary key
my $allitemtypes = C4::Data::ItemType->select_all;    # ref to array of objects

print "Book Item Type: ", $bookitemtype->description, "\n";
print "All Item Types:\n";
printf "%2s %s\n", $_->itemtype, $_->description for @$allitemtypes;


# update

$bookitemtype->description('Libres');
$bookitemtype->_commit;

# insert

C4::Data::ItemType->insert({itemtype->'N1',description=>'new item type' ... etc});

# delete

C4::Data::ItemType->delete('N1');


BTW: what is the C4 namesapce? why is it called C4?


cheers
rickw



-- 
________________________________________________________________
Rick Welykochy || Praxis Services || Internet Driving Instructor

When the power of love overcomes the love of power,
the world will know peace.
      -- Jimi Hendrix



More information about the Koha-devel mailing list