|
Posted by John Siracusa on March 21, 2005, 4:24 pm
Please log in for more thread options
Rose::DB::Object provides an object representation of databse rows.
It addresses some of the same problems as Class:DBI, Alzabo, et al,
but it takes a slightly different appraoch. It's still in the early
stages of development, but it's fully documented and has a large test
suite already.
I'm looking for developers who are either unsatisfied with existing
OO-RDBMS mapping modules or are just curious to help me ring the
code out. Comments, suggestion, and of course bug reports are very
welcome.
Excerpts from the documentation follow.
-John
---
NAME
Rose::DB::Object - Object representation of a single row in a database
table.
SYNOPSIS
package Category;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
__PACKAGE__->meta->table('categories');
__PACKAGE__->meta->columns
(
id => { type => 'int', primary_key => 1 },
name => { type => 'varchar', length => 255 },
description => { type => 'text' },
);
__PACKAGE__->meta->add_unique_key('name');
__PACKAGE__->meta->initialize;
...
package Product;
use Rose::DB::Object;
our @ISA = qw(Rose::DB::Object);
__PACKAGE__->meta->table('products');
__PACKAGE__->meta->columns
(
id => { type => 'int', primary_key => 1 },
name => { type => 'varchar', length => 255 },
description => { type => 'text' },
category_id => { type => 'int' },
status =>
{
type => 'varchar',
check_in => [ 'active', 'inactive' ],
default => 'inactive',
},
start_date => { type => 'datetime' },
end_date => { type => 'datetime' },
date_created => { type => 'timestamp', default => 'now' },
last_modified => { type => 'timestamp', default => 'now' },
);
__PACKAGE__->meta->add_unique_key('name');
__PACKAGE__->meta->foreign_keys
(
category =>
{
class => 'Category',
key_columns =>
{
category_id => 'id',
}
},
);
__PACKAGE__->meta->initialize;
...
$product = Product->new(id => 123,
name => 'GameCube',
status => 'active',
start_date => '11/5/2001',
end_date => '12/1/2007',
category_id => 5);
$product->save or die $product->error;
...
$product = Product->new(id => 123);
$product->load or die $product->error;
print $product->category->name;
$product->end_date->add(days => 45);
$product->save or die $product->error;
...
package Product::Manager;
use Rose::DB::Object::Manager;
our @ISA = qw(Rose::DB::Object::Manager);
sub get_products
{
my $class = shift;
Rose::DB::Object::Manager->get_objects(
object_class => 'Product', @_)
}
sub get_products_iterator
{
my $class = shift;
Rose::DB::Object::Manager->get_objects_iterator(
object_class => 'Product', @_)
}
sub get_products_count
{
my $class = shift;
Rose::DB::Object::Manager->get_objects_count(
object_class => 'Product', @_)
}
...
#
# Get a reference to an array of objects
#
$products =
Product::Manager->get_products
(
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
sort_by => 'category_id, start_date DESC',
limit => 100
)
or die Product::Manager->error;
foreach my $product (@$products)
{
print $product->id, ' ', $product->name, "n";
}
#
# Get objects iterator
#
$iterator =
Product::Manager->get_products_iterator
(
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
sort_by => 'category_id, start_date DESC',
limit => 100
)
or die Product::Manager->error;
while($product = $iterator->next)
{
print $product->id, ' ', $product->name, "n";
}
print $iterator->total;
#
# Get objects count
#
$count =
Product::Manager->get_products_count
(
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
limit => 100
);
die Product::Manager->error unless(defined $count);
print $count; # or Product::Manager->total()
#
# Get objects and sub-objects in a single query
#
$products =
Product::Manager->get_products
(
with_objects => [ 'category' ],
query =>
[
category_id => [ 5, 7, 22 ],
status => 'active',
start_date => { lt => '15/12/2005 6:30 p.m.' },
name => { like => [ '%foo%', '%bar%' ] },
],
sort_by => 'category_id, start_date DESC',
limit => 100
)
or die Product::Manager->error;
foreach my $product (@$products)
{
print $product->name, ': ', $product->category->name, "n";
}
|
|
Posted by John Siracusa on March 27, 2005, 12:28 am
Please log in for more thread options
if we try and establish some industry in our own community,
then we're developing to the position where we are creating employment
for our own kind. Once you gain control of the economy of your own
community, then you don't have to picket and boycott and beg some
cracker downtown for a job in his business.
The social philosophy of black nationalism only means that we have to
get together and remove the evils, the vices, alcoholism, drug
addiction, and other evils that are destroying the moral fiber of our
community. We our selves have to lift the level of our community, the
standard of our community to a higher level, make our own society
beautiful so that we will be satisfied in our own social circles and
won't be running around here trying to knock our way into a social
circle where we're not wanted. So I say, in spreading a gospel such as
black nationalism, it is not designed to make the black man re-evaluate
the white man -- you know him already -- but to make the black man
re-evaluate himself. Don't change the white man's mind -- you can't
change his mind, and that whole thing about appealing to the moral
conscience of America -- America's conscience is bankrupt. She lost all
conscience a long time ago. Uncle Sam has no conscience.
They don't know what morals are. They don't try and eliminate an evil
because it's evil, or because it's illegal, or because it's immoral;
they eliminate it only when it threatens their existence. So you're
wasting your time appealing to the moral conscience of a bankrupt man
like Uncle Sam. If he had a conscience, he'd straighte
|
| Similar Threads | Posted | | [RDBO] ANNOUNCE: Rose::DB::Object 0.71 released | April 14, 2006, 3:29 pm |
| [RDBO] ANNOUNCE: Rose::DB::Object 0.72 released | April 19, 2006, 9:03 am |
| [RDBO] ANNOUNCE: Rose::DB::Object 0.722 released | April 27, 2006, 8:25 pm |
| [RDBO] ANNOUNCE: Rose::DB::Object 0.73 released | June 7, 2006, 3:14 pm |
| ANNOUNCE: OOPS 1.004 - Object Oriented Persistent Store | July 4, 2006, 1:53 pm |
| How should I announce the list of delayed class/object/method loaders? | October 25, 2005, 9:54 am |
| AppConfig: how to reset object? | October 1, 2004, 9:20 am |
| Can't find loadable object | November 19, 2004, 1:05 pm |
| Can't locate loadable object | August 4, 2005, 12:18 am |
| Set::Object installation Problem | October 14, 2006, 6:04 am |
|