APM: Database wrapper classes

Hrunting hrunting at texas.net
Tue Aug 13 09:38:16 CDT 2002


On Tue, 13 Aug 2002, Wayne Walker wrote:

: Hi Everyone,
: 
: First we should be having a meeting in 8 days. Someone will get out a
: notice soon.
: 
: But, more importantly, I want other peoples inputs on good ways to wrap
: database access in some kind of class or package.
: 
: Let's say I have a project that uses three database tables and I need/want
: to hide/bury the SQL away from the application developers (who are new
: to perl, every piece I can hide from them is one less thing they need
: to learn right now).
: 
: I could write some classes that just make the SQL disappear:
: 
: Person
:         add(%data)
:         delete($id)
:         get($id)
: Address
:         add(%data)
:         delete($id)
:         get($id)
: Relations
:         add(%data)
:         delete($id)
:         get($id)

That is the best way.  Hide the logic behind the middle layer.  What I
like to do is create a generic *::DBI class that inherits from DBI and
stores the information for connecting to the database I need (through
methods like *::DBI->connect() or *::DBI->connect_ro()) and have the
wrapper classes use that (so they don't have to know anything about
user/pass information, etc.

If I ever need to do more complex work than my wrapper classes allow, I
just use the *::DBI class to pull my database connection and do the
work manually.

Generally, if I'm doing complex SQL outside of my wrapper classes, it's
for specific queries that aren't handled well by a wrapping model.





More information about the Austin mailing list