[CDBI] multiple tables with same structure

Juan Camacho jc5826 at gmail.com
Wed Oct 4 17:22:09 BST 2006


On 9/18/06, Ben Lavender <blavender at gmail.com> wrote:
> Hi all,
>
> But that is, naturally, only half the battle when dealing with CDBI,
> for the obvious reason that CDBI maps classes to table.  I'm basically
> trying to find a way to tell CDBI to fetch an object of type x from
> table y, and the next time the script is run it might be table z, but
> the object will still be of type x.
>

Have you tried changing the table name at run-time? e.g.
  package main;
  use Music::Artist;
  Music::Artist->table('z').

Not sure how much havoc the above will cause given you are messing
with class data, but it should work for simple cases, e.g. search,
retrieve, retrieve_all scenarios.

Also, see "Using multiple databases" Wiki entry at
http://wiki.class-dbi.com/wiki/Using_multiple_databases
It doesn't necessarily address your issue directly, but maybe you'll
get some inspiration from it :)

Also investigate using alternative packages Rose::DB or DBIx::Class
instead of CDBI.



More information about the ClassDBI mailing list