Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 4. Objects, Databases, and Appli... > Database Abstraction - Pg. 134

CD->new({ title => "The Dark Side of The Moon", publishdate => Time::Piece->strptime("2000-04-06", "%y-%m-%d"), songs => [ map { CD::Song->new({ name => $_ }) } "Speak To Me/Breathe", "On The Run", "Time", "The Great Gig in the Sky", "Money", "Us And Them", "Any Colour You Like", "Brain Damage", "Eclipse", ], }) ); $pfloyd->popularity("legendary"); $storage->update($pfloyd); $storage->id($cd); So far we've demonstrated three points about Tangram's update facilities. The final aspect of Tangram's CRUD--deleting objects--is done with $storage->erase( ) : my (@gonners) = $storage->select ($r_artist, $r_artist->{popularity} eq "one hit wonder"); $storage->erase(@gonners); Tangram has excellent transaction support, mature object caching abilities, functions to deal with short-term dirty read problems, and the orthogonal ability to perform schema migration using two database handles. Its debugging output, selected with the environment variable TANGRAM_TRACE or by setting the Perl variable $Tangram::TRACE to a filehandle, provides a clear picture of what queries are being run by your program. Its major downsides are that it does not support partially reading objects (only com- plete rows), it cannot easily be queried with raw SQL expressions, and it does not deal with indexing (the assumption being that the database administrator can set up appropriate indexes, or that creating such indexes happens independently of the nor- mal schema deployment). Database Abstraction Tangram has given us a way to store and retrieve objects in a database. The other side of the coin is the situation of having an existing database and wanting to get a view of it in terms of Perl objects. This is a very subtle distinction, but an important one. In the case of Tangram (and indeed, Pixie), we didn't really care what the database schema was, because the database was just an incidental way for Tangram to store its stuff. It could create whatever tables and columns it wanted; what we really care about is what the objects look like. In the current case, though, we already have the database; we have a defined schema, and we want the database abstraction tool to work around that and tell us what the objects should look like. 134 | Chapter 4: Objects, Databases, and Applications This is the Title of the Book, eMatter Edition Copyright © 2007 O'Reilly & Associates, Inc. All rights reserved.