From 6858ddc4b49afe3cd4a69b3e6eeeb76fa7ac27c8 Mon Sep 17 00:00:00 2001 From: Jacob Helwig Date: Sat, 10 May 2008 01:21:36 -0700 Subject: [PATCH] Bring a few more tables into the Class::DBI fold. --- perl_lib/Kamitsukai/Table/AmazonImages.pm | 21 ++ perl_lib/Kamitsukai/Table/Book.pm | 363 ++++-------------------------- 2 files changed, 64 insertions(+), 320 deletions(-) create mode 100644 perl_lib/Kamitsukai/Table/AmazonImages.pm rewrite perl_lib/Kamitsukai/Table/Book.pm (99%) diff --git a/perl_lib/Kamitsukai/Table/AmazonImages.pm b/perl_lib/Kamitsukai/Table/AmazonImages.pm new file mode 100644 index 0000000..3b6d2dc --- /dev/null +++ b/perl_lib/Kamitsukai/Table/AmazonImages.pm @@ -0,0 +1,21 @@ +package Kamitsukai::Table::AmazonImages; + +use strict; +use Perl6::Parameters; + +use base qw/Kamitsukai::Database::Table/; + +Kamitsukai::Table::Book->table('library_amazon_images'); + +Kamitsukai::Table::Book->columns( + All => qw/ + asin + category + size + width + height + url + /, +); + +1; diff --git a/perl_lib/Kamitsukai/Table/Book.pm b/perl_lib/Kamitsukai/Table/Book.pm dissimilarity index 99% index e92c67a..713c9ff 100644 --- a/perl_lib/Kamitsukai/Table/Book.pm +++ b/perl_lib/Kamitsukai/Table/Book.pm @@ -1,320 +1,43 @@ -use DBIx::SearchBuilder; - -package Kamitsukai::Book; -use base qw/DBIx::SearchBuilder/; - -sub _Init { - my $self = shift; - $self->Table('book_info'); - return $self->SUPER::_Init(@_); -} - -sub NewItem { - my $self = shift; - - # MyThing is a subclass of DBIx::SearchBuilder::Record - return ( MyThing->new ); -} ## end sub NewItem - -sub Create { - my $self = shift; - my %args = ( - Id => '0', - ISBN => '', - EAN => '', - Title => '', - Binding => '', - DeweyDecimal => '', - Publisher => '', - Published => '', - Released => '', - Studio => '', - Pages => '0', - Height => '0', - HeightUnits => '', - Length => '0', - LengthUnits => '', - Width => '0', - WidthUnits => '', - Weight => '0', - WeightUnits => '', - ASIN => '', - DetailPageURL => '', - @_ - ); - $self->SUPER::Create( - Id => $args{'Id'}, - ISBN => $args{'ISBN'}, - EAN => $args{'EAN'}, - Title => $args{'Title'}, - Binding => $args{'Binding'}, - DeweyDecimal => $args{'DeweyDecimal'}, - Publisher => $args{'Publisher'}, - Published => $args{'Published'}, - Released => $args{'Released'}, - Studio => $args{'Studio'}, - Pages => $args{'Pages'}, - Height => $args{'Height'}, - HeightUnits => $args{'HeightUnits'}, - Length => $args{'Length'}, - LengthUnits => $args{'LengthUnits'}, - Width => $args{'Width'}, - WidthUnits => $args{'WidthUnits'}, - Weight => $args{'Weight'}, - WeightUnits => $args{'WeightUnits'}, - ASIN => $args{'ASIN'}, - DetailPageURL => $args{'DetailPageURL'}, - ); - -} ## end sub Create - -sub _CoreAccessible { - { - - Id => { - read => 1, - sql_type => 4, - length => 11, - is_blob => 0, - is_numeric => 1, - type => 'int(11)', - default => '' - }, - ISBN => { - read => 1, - write => 1, - sql_type => 12, - length => 10, - is_blob => 0, - is_numeric => 0, - type => 'varchar(10)', - default => '' - }, - EAN => { - read => 1, - write => 1, - sql_type => 12, - length => 13, - is_blob => 0, - is_numeric => 0, - type => 'varchar(13)', - default => '' - }, - Type => { - read => 1, - write => 1, - sql_type => 12, - length => 16, - is_blob => 0, - is_numeric => 0, - type => 'varchar(16)', - default => '' - }, - Title => { - read => 1, - write => 1, - sql_type => -4, - length => 0, - is_blob => 1, - is_numeric => 0, - type => 'text', - default => '[No Title]' - }, - Binding => { - read => 1, - write => 1, - sql_type => 12, - length => 255, - is_blob => 0, - is_numeric => 0, - type => 'varchar(255)', - default => '' - }, - DeweyDecimal => { - read => 1, - write => 1, - sql_type => 6, - length => 0, - is_blob => 0, - is_numeric => 1, - type => 'float', - default => '' - }, - Publisher => { - read => 1, - write => 1, - sql_type => -4, - length => 0, - is_blob => 1, - is_numeric => 0, - type => 'text', - default => '' - }, - Published => { - read => 1, - auto => 1, - sql_type => 9, - length => 0, - is_blob => 0, - is_numeric => 0, - type => 'date', - default => '' - }, - Released => { - read => 1, - auto => 1, - sql_type => 9, - length => 0, - is_blob => 0, - is_numeric => 0, - type => 'date', - default => '' - }, - Studio => { - read => 1, - write => 1, - sql_type => -4, - length => 0, - is_blob => 1, - is_numeric => 0, - type => 'text', - default => '' - }, - Pages => { - read => 1, - write => 1, - sql_type => 4, - length => 11, - is_blob => 0, - is_numeric => 1, - type => 'int(11)', - default => '0' - }, - Height => { - read => 1, - write => 1, - sql_type => 4, - length => 11, - is_blob => 0, - is_numeric => 1, - type => 'int(11)', - default => '0' - }, - HeightUnits => { - read => 1, - write => 1, - sql_type => 12, - length => 255, - is_blob => 0, - is_numeric => 0, - type => 'varchar(255)', - default => '' - }, - Length => { - read => 1, - write => 1, - sql_type => 4, - length => 11, - is_blob => 0, - is_numeric => 1, - type => 'int(11)', - default => '0' - }, - LengthUnits => { - read => 1, - write => 1, - sql_type => 12, - length => 255, - is_blob => 0, - is_numeric => 0, - type => 'varchar(255)', - default => '' - }, - Width => { - read => 1, - write => 1, - sql_type => 4, - length => 11, - is_blob => 0, - is_numeric => 1, - type => 'int(11)', - default => '0' - }, - WidthUnits => { - read => 1, - write => 1, - sql_type => 12, - length => 255, - is_blob => 0, - is_numeric => 0, - type => 'varchar(255)', - default => '' - }, - Weight => { - read => 1, - write => 1, - sql_type => 4, - length => 11, - is_blob => 0, - is_numeric => 1, - type => 'int(11)', - default => '0' - }, - WeightUnits => { - read => 1, - write => 1, - sql_type => 12, - length => 255, - is_blob => 0, - is_numeric => 0, - type => 'varchar(255)', - default => '' - }, - ASIN => { - read => 1, - write => 1, - sql_type => 12, - length => 255, - is_blob => 0, - is_numeric => 0, - type => 'varchar(255)', - default => '' - }, - DetailPageURL => { - read => 1, - write => 1, - sql_type => -4, - length => 0, - is_blob => 1, - is_numeric => 0, - type => 'text', - default => '' - }, - Updated => { - read => 1, - auto => 1, - sql_type => 11, - length => 0, - is_blob => 0, - is_numeric => 0, - type => 'datetime', - default => '' - } }; -} ## end sub _CoreAccessible - -sub Load { - my $self = shift; - my $id = shift; - - if ( $id =~ /^\d+$/ ) { - my ($bookid,$msg) = $self->LoadById($id); - - unless ($self->Id) { - return (undef); - } - } else { - return (undef); - } - - return ($self->Id); -} +package Kamitsukai::Table::Book; + +use strict; +use Perl6::Parameters; + +use base qw/Kamitsukai::Database::Table/; + +use aliased 'Kamitsukai::Table::AmazonImages'; + +Kamitsukai::Table::Book->table('library_book_info'); + +Kamitsukai::Table::Book->columns( + All => qw/ + id + isbn + ean + title + binding + deweydecimal + publisher + published + released + studio + pages + height + heightunits + length + lengthunits + width + widthunits + weight + weightunits + asin + detailpageurl + updated + /, +); + +sub images($self) { + return AmazonImages->search(asin => $self->asin()); +} + +1; -- 2.11.4.GIT