Using DBI

Database Interface for perl

Database Independence

Use the same application code for MySQL, postgres, oracle,... (well, almost)

Similar to JDBC in java

Example code: SELECT

use DBI;

my $dbh = DBI->connect('dbi:Pg:dbname=toy2;host=scabrous');

my $rows = 
  $dbh->selectall_arrayref('SELECT * FROM gene NATURAL JOIN gene_function');
foreach my $row (@$rows) {
    foreach my $column (@$row) {
        print "$column, ";
    }
    print "\n";
}
    
Click here to see download

The output looks like this:
gn00002     , foo, 35A7, transmembrane receptor,
gn00003     , bar, 60F1, glutamine-tRNA ligase,
gn00003     , bar, 60F1, ATP binding,
gn00004     , whee, 58C2, GPCR,
gn00004     , whee, 58C2, taste receptor,
    

DBI has a lot more to it - type "man DBI" for full instructions.

DBI is great as an API to the relational layer. However, as all queries return relations which are "flat" we lose the structure of the underlying data. Most java/perl/python/C programmers would prefer to work with either some kind of data structure or object model. We have to go beyond DBI to get this.

Gadfly object-relational model

The Gadfly genome annotation database uses a custom code layer for mapping between the Gadfly object model and the relational model. This is a bit of a hack, leads to inefficient querying, and it proves hard to maintain. Furthermore, by forcing the application programmer to go through an API the range of queries available is limited.

The GO database uses a similar system.

There are other object-relational mapping systems out there - both commercial and open source. These are all crap, because of the fundamental incompatibility of the two paradigms.


Previous | Next |
chris mungall
Last modified: Mon Jan 13 10:29:53 PST 2003