Friday, August 13, 2010

DBIx::Class join, prefetch

Over the last 15 years I've joined two database tables into a one-to-many relationship about a billion times. But I've never had any software let me loop the left table and right tables separately before. Turns out this magic has been in DBIx::Class for several years.

Runnable demo.

When table 'foo' is in a one-to-many relationship with table 'bar', you can:

my $foo_rs = $schema->resultset('Foo')->search(
{},
{
join => 'bars',
prefetch => 'bars',
order_by => 'me.id',
}
);

while (my $foo = $foo_rs->next) {
printf "%s\n", $foo->id;
if (my $bar_rs = $foo->bars) {
while (my $bar = $bar_rs->next) {
printf " %s\n", $bar->desc;
}
}
}
Output:

1
2
aaa
bbb
ccc
3
Still one SQL statement against the database (fast!). Much prettier than ugly manual de-duping of redundant columns.

Saturday, August 7, 2010

quibids.com, you're my hero!

Holy crap! The people running this auction site must be making a fortune!

Quibids.com is an auction site where you pay to bid. Each bid costs $0.60 and raises the bid price on the item by 1 penny. Items start at 1 penny. I'm watching the bids on a $1600 laptop climb from $50 up to $73 and beyond. A $1600 laptop for only $73? What a bargain, right? Yup, if everyone else would stop bidding and let you win. Hint: They won't.

It says right here that this item "recently sold for $422.59." Someone saved $1200! Good for them! In the process, quibids.com raked in $25,355.40 (42,259 * $0.60) in fees on the sale of a single $1,600 laptop! HOLY CRAP!

Capitalism rules! I need to launch one of these sites and only charge $0.50 per bid!



Update: This ad says "Honda Civic Sold for $2,642!" There's another $158,520 in bidding fees for Quibids.com. Also, for the company spin: Does QuiBids make excessive profit on their auctions? (Of course not! We have to pay rent and stuff! -grin-)