Rose::DB::Object

Extensible, high performance object-relational mapper (ORM)
Download

Rose::DB::Object Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • John Siracusa
  • Publisher web site:
  • http://search.cpan.org/~jsiracusa/

Rose::DB::Object Tags


Rose::DB::Object Description

Extensible, high performance object-relational mapper (ORM) Rose::DB::Object is a Perl module for objects that encapsulate a single row in a database table. Rose::DB::Object-derived objects are sometimes simply called "Rose::DB::Object objects" in this documentation for the sake of brevity, but be assured that derivation is the only reasonable way to use this class.Rose::DB::Object inherits from, and follows the conventions of, Rose::Object. See the Rose::Object documentation for more information.For an informal overview of this module distribution, consult the Rose::DB::Object::Tutorial.RestrictionsRose::DB::Object objects can represent rows in almost any database table, subject to the following constraints. * The database server must be supported by Rose::DB. * The database table must have a primary key. * The primary key must not allow null values in any of its columns.Although the list above contains the only hard and fast rules, there may be other realities that you'll need to work around.The most common example is the existence of a column name in the database table that conflicts with the name of a method in the Rose::DB::Object API. There are two possible workarounds: either explicitly alias the column, or define a mapping function. See the alias_column and column_name_to_method_name_mapper methods in the Rose::DB::Object::Metadata documentation for more details.There are also varying degrees of support for data types in each database server supported by Rose::DB. If you have a table that uses a data type not supported by an existing Rose::DB::Object::Metadata::Column-derived class, you will have to write your own column class and then map it to a type name using Rose::DB::Object::Metadata's column_type_class method, yada yada. (Or, of course, you can map the new type to an existing column class.)The entire framework is extensible. This module distribution contains straight-forward implementations of the most common column types, but there's certainly more that can be done. Submissions are welcome.SYNOPSIS ## For an informal overview of Rose::DB::Object, please ## see the Rose::DB::Object::Tutorial documentation. The ## reference documentation follows. ## First, set up your Rose::DB data sources, otherwise you ## won't be able to connect to the database at all. See ## the Rose::DB documentation for more information. For ## a quick start, see the Rose::DB::Tutorial documentation. ## ## Create classes - two possible approaches: ## # # 1. Automatic configuration # package Category; use base qw(Rose::DB::Object); __PACKAGE__->meta->setup ( table => 'categories', auto => 1, ); ... package Price; use base qw(Rose::DB::Object); __PACKAGE__->meta->setup ( table => 'prices', auto => 1, ); ... package Product; use base qw(Rose::DB::Object); __PACKAGE__->meta->setup ( table => 'products', auto => 1, ); # # 2. Manual configuration # package Category; use base qw(Rose::DB::Object); __PACKAGE__->meta->setup ( table => 'categories', columns => , unique_key => 'name', ); ... package Price; use base qw(Rose::DB::Object); __PACKAGE__->meta->setup ( table => 'prices', columns => , unique_key => , ); ... package Product; use base qw(Rose::DB::Object); __PACKAGE__->meta->setup ( table => 'products', columns => , default => 'inactive', }, start_date => { type => 'datetime' }, end_date => { type => 'datetime' }, date_created => { type => 'timestamp', default => 'now' }, last_modified => { type => 'timestamp', default => 'now' }, ], unique_key => 'name', foreign_keys => , relationships => , ); ... # # Example usage # $product = Product->new(id => 123, name => 'GameCube', status => 'active', start_date => '11/5/2001', end_date => '12/1/2007', category_id => 5); $product->save; ... $product = Product->new(id => 123); $product->load; # Load foreign object via "one to one" relationship print $product->category->name; $product->end_date->add(days => 45); $product->save; ... $product = Product->new(id => 456); $product->load; # Load foreign objects via "one to many" relationship print join ' ', $product->prices; ...


Rose::DB::Object Related Software