Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Rolling my own database abstraction

by stonecolddevin (Parson)
on Oct 18, 2004 at 00:48 UTC ( [id://400014]=perlquestion: print w/replies, xml ) Need Help??

stonecolddevin has asked for the wisdom of the Perl Monks concerning the following question:

Hey all,

I'm looking to write my own database abstraction layer, something that basically sits right on top of DBI.

Basically I just want to package a bunch of my functions into one module, and organize it so I don't have to do much other than call the function and have the appropriate data sent or returned.

I read an article here:http://www.phpdeveloper.org/section/tutorial/35, on how to do it in PHP, and I have been trying to "translate" it since.

Can any of you wise monks lend a hand?
Thanks in advance,
dhoss

UPDATE: I would like to write and design this in/with OO, if that is of any help.

meh.

Replies are listed 'Best First'.
Re: Rolling my own database abstraction
by kvale (Monsignor) on Oct 18, 2004 at 01:05 UTC
    Class::DBI is a fine example of an object-oriented DBI abstraction layer. Use it directly, or mine it for implementation ideas in your own module.

    -Mark

      Much thanks, kvale.

      I've been leaning towards Class::DBI for some time now, I think I just need to get up over the hump and get down and dirty with it

      Thanks for the nudge :-)

      meh.
Re: Rolling my own database abstraction
by DaveH (Monk) on Oct 18, 2004 at 01:38 UTC

    Perhaps you want the "Lazy" version of Class::DBI - DBIx::LazyMethod. Looks about the shortest possible code to achieve OO generic database access.

    Hope this helps. Not tried this module personally.

    Cheers,

    -- Dave :-)


    $q=[split+qr,,,q,~swmi,.$,],+s.$.Em~w^,,.,s,.,$&&$$q[pos],eg,print
      shortest possible code to achieve OO generic database access
      Take a look at Class::Tables. Just add two lines of code. No datastructure describing your schema. Now that's lazy ;)

      This module was born because I got sick of talking about my schema twice: once to the database and once to the database persistence layer. Now I can write simple database-driven apps really fast.

      blokhead

      Oooo, that looks fuN!!!
      Short, sweet and simple.

      Thanks, I'll definitely check it out.
      meh.
Re: Rolling my own database abstraction
by perrin (Chancellor) on Oct 18, 2004 at 03:02 UTC
    That PHP article is about compensating for the lack of a single shared database API in PHP. (There are some, but many PHP devs resist them because they claim it hurts performance too much.) In Perl, you already have DBI, which works across databases and offers all of the functionality shown in the article.

    The other suggestions in this thread are fine, but if all you want is to get to the level shown in that article, you've already got it with DBI.

      I tend to bounce back and forth between Perl and PHP depending on the language chosen for the project. I've started writing a simple DB table-wrapper in both Perl and PHP with the same methods. Whenever I switch languages, I often have to readjust to the database APIs - which are often similar enough to be confusing. I've never used a PHP native db interface - only the DB generic Pear::DB and superior AdoDB.

      The great thing about sharing a similar abstraction in both languages is that I can use either Perl's CGI::Application or the PHP port and pretty much develop with a similar structure, regardless of the language. My preference is Perl of course - it has a number of fantastic tricks up its sleeve that make it a joy to use. I loooove CGI::Application::Plugin::ValidateRM

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 15:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found