Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Handling near-redundant SQL queries

by blokhead (Monsignor)
on Sep 01, 2004 at 01:08 UTC ( [id://387367]=note: print w/replies, xml ) Need Help??


in reply to Handling near-redundant SQL queries

I wrote Class::Tables just for this kind of situation. You have a schema sitting there in the database, and you want a nice interface with minimal effort. In this case, the schema might need a minor change -- unless you're using SQLite, you'll also need an 'id' column for each of the many-to-many mapping tables. Apart from that little change, the module will automatically do the right thing here... Even match up the singular "company_id" column with the plural "companies" table, a feature I'm quite proud of. All it takes is 2 extra lines of code, and you have the proper object persistence classes available. Check out the pod.

The newest development version also supports many-to-many accessors directly (thanks to contributions from elusion) which your schema will greatly benefit from.

If you need more complex functionality, Class::DBI is the way to go, so check them both out to see which is a better fit for your goals.

Either way, with object-persistence modules like this, you can perform a query and get back a collection of objects. Then you should really be sending the results to an HTML templating system. It should be the current template that decides what fields from the objects should be shown (phone number, etc). The core application logic shouldn't have to be burdened with that. Certainly you wouldn't want a separate function in your code for each possible combination of columns to fetch/show.

blokhead

  • Comment on Re: Handling near-redundant SQL queries

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://387367]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-18 03:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found