Re: dynamically defining base class for a CDBI table module
[prev]
[thread]
[next]
[Date index for 2005/03/11]
On Fri, Mar 11, 2005 at 08:55:22AM -0500, Gianni, Andrew wrote:
> > On Thu, 2005-03-10 at 16:35 -0500, Gianni, Andrew wrote:
> > > Never mind, I think I figured it out. It's pretty simple actually; I
> > > just need to update the ISA array for each table module that I
> import to
> > > point to the module that contains the db_Main that I want to use.
> >
> > You've totally lost me. I thought you just said that you don't need
> to
> > use different database connections. If that's the case, and your base
> > classes don't define any additional methods, why are you switching
> base
> > classes?
>
> The issue is that, by default, these tables will use the database
> connections defined by their parent class (the schema owner's username
> and password). But in a particular project, I want all tables to share a
> single connection, owned by that particular project. My idea was that in
> a given project, I would run a require on all the modules I need
> (multiple tables across multiple schemas) and then redefine them as
> sub-classes of the project's parent cdbi class, thus allowing them to
> all share a single connection.
I would've thought the easy answer would be to have an empty 'Schema1'
base class and load a Schema1::Base that pushes itself into Schema1's ISA
- that way you only need to change the @ISA of a class per schema instead
of a class per table.
> However, if this isn't going to work under mod_perl, that may be an
> issue. It's looking more and more like Class::DBI::Factory is the
> answer.
Have a look at Safe::World - you could load the table classes in one world
then derive a fresh world for each app where the base classes are altered
appropriately.
I've been looking at doing a module around Safe::World that does this sort
of stuff for mod_perl apps with a minimum of hassle. This will go faster if
anybody else is interested in it :)
--
Matt S Trout Brag sheet: http://trout.me.uk/services.html
LAMP, Infrastructure Contact: services@xxxxx.xx.xx
and Automation
specialist Do it once. Do it right.