DBIx::SearchProfiles

When you get !#$*# tired

of writing out the same SQL

all of the time...

SearchProfiles Features

Builds simple queries for you automatically.

You can build your own complex queries yourself and use the SearchProfiles methods on them easily.

Decouples SQL code from the rest of your application.

SearchProfiles Drawbacks

Indexing is broken on CPAN

perl -MCPAN -e 'install F/FR/FRAJULAC/SearchProfiles-0.11.tar.gz'

Maybe it makes things a little too easy to cheat.

Access Methods

Profiles can be defined for three different access methods:

SQL

You provide the SQL and get back what you ask for.

Record-Based

You define the table schema, and it handles the SQL.

Template-Based

You provide some of the SQL, and it handles the rest.

Methods

Within each access type, there are 5 methods of operation:

Get

Returns hashref.

Search

Returns Array of Hashrefs

Can specify ordering info, as well as limits and offsets.

Insert

Update

Delete

SQL Access

Lets you run whatever SQL you want directly from your code.

$profile->sql_get(“Select * from table where a = ?”, $val);

You can do whatever SQL lets you do.

You loose the benefits of decoupling your SQL from your code.

Record Profiles

To use Record based access, you need to define your database profile ahead of time:

my $profile = {

customer =>

{

fields => [qw( name, phone )],

keys => [qw( customer_no )],

table => “customer”,

},

order_items =>

{

fields => [qw( quantity subtotal ) ],

keys => [ qw( order_no code ) ],

table => "order_items",

},

};

my $DB = DBIx::SearchProfiles->new( $dbh, $profile );

Record Access

$DB->record_get( “customer”, 1024 );

$DB->record_search( “ordered_items”,

{ order_no => 1234 } );

$DB->record_insert( “customer”,

{ customer_no => 9324,

name => “joee” } );

$DB->record_insert( “customer”,

{ customer_no => 9324,

name => “Joe” } );

$DB->record_delete( “customer”, {customer_no => 9324} );

Template Profiles

Templates let you de-couple advanced SQL from your code:

my $profile = {

“shipping_info” => {

query => q{ SELECT order_no, name, phone

FROM orders, customer

WHERE orders.customer_no = customer.customer_no

AND orders.shipped = 0

AND orders.customer_no = ? },

params => [ qw( customer_no ) ],

}

}

my $DB = DBIx::SearchProfiles->new( $dbh, $profile );

$DB->template_search( “shipping_info”, { customer_no => 122 } );

Conclusions

This module saves me time.

This module saves me from making mistakes.

This module allows my code to scale better.

This module is easy to learn (and remember).

I like this module.

Dan Wright

2005-05-11T16:13:24