mbethke has asked for the wisdom of the Perl Monks concerning the following question:
There's heaps of database abstraction modules in Perl but it seems that while abstraction always means "You don't have to deal with messy C interfaces", and sometimes "You can write SQL in Perl", it hardly ever means "we'll take care of data type idiosyncrasies for you". I need something like that.
My problem (briefly mentioned in my announcement of Ashafix) is this: I've used a couple of DBMS layers but all programs have been tied to one particular DBMS. Now I want to write one that runs unchanged on at least PostgreSQL and MySQL and my first problem is the handling of booleans. Pg uses an own type that returns 't' or 'f' while MySQL by convention uses TINYINT that is set to zero or non-zero. Currently I'm using DBIx::Simple and I'd prefer to keep it fairly slim. My ideas so far:
- Define an ENUM in MySQL to emulate the Pg behavior. Doesn't work because other software is using the database too and would get very confused.
- Use DBIx::Class, write my own InflateColumn::Bool and a primitive Bool class that uses a tied hash or something to give the usual zero-or-nonzero-scalar behavior when used in boolean context.
Disadvantage: that's about as fat as it gets. - Subclass DBIx::Simple, feed it a simple column=>type mapping for each table I'll use and make all retrieval methods use a hash()/hashes() method internally so I can do the mapping myself.
Disadvantage: smells inefficient (although it's probably still much faster than DBIx::Class), may be reinventing the wheel.
Have I by any chance overlooked something on CPAN that would let me do this in a simpler way?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Database abstraction including data types ( $dbh->{pg_bool_tf} )
by erix (Prior) on May 20, 2012 at 19:49 UTC | |
by Anonymous Monk on May 20, 2012 at 21:00 UTC | |
by Anonymous Monk on May 20, 2012 at 21:06 UTC | |
by mbethke (Hermit) on May 22, 2012 at 05:36 UTC | |
by mbethke (Hermit) on May 22, 2012 at 05:12 UTC | |
Re: Database abstraction including data types
by sundialsvc4 (Abbot) on May 20, 2012 at 22:43 UTC | |
by mbethke (Hermit) on May 22, 2012 at 06:03 UTC |