[sf-perl] ORM vs. DBI

Fred Moyer fred at redhotpenguin.com
Mon Feb 28 09:02:38 PST 2011


On Sat, Feb 26, 2011 at 11:00 PM, Michael Friedman
<friedman at highwire.stanford.edu> wrote:
> Fellow Perl Mongers,
>
> I finally got around to reading up on and trying out DBIx::Class. It looks pretty neat, but after loading up a complex DB (108 tables) and writing a short test script, I really don't understand why you'd want to use it over using just regular DBI and SQL. Maybe it's because I knew SQL before I knew Perl and I'm training in looking at things in a SQL way, but I'm not so sure.
>
> So I'd like to throw the floor open to discussion. Why would you want to use DBIx::Class (or any Object-Relational Manager) instead of writing classes that call the DB directly through DBI?

Once you understand how to use DBIx::Class, it makes your life a lot
simpler.  You don't have to think about what fields you're retrieving
with sql statements, whether or not you typed in the wrong key for a
hash slice lookup, etc, etc.

If writing raw sql with DBI is a sledgehammer, DBIx::Class is a
wrecking ball.  It takes some review and time to learn the API, but
you can get a lot more done in a much shorter amount of time, and
still be able to use raw SQL for those queries you need to optimize.

Best of all, you can point it at your database and have it extract a
full resultset library from it, to which you can add your own methods.
 If making sure your sql is exactly the way you want it in every case,
DBIx::Class is probably not for you.  But if you want to get business
goals accomplished, and worry about optimizing thing later, it is a
choice tool.


More information about the SanFrancisco-pm mailing list