[Dbix-class] Splitting Database Handle for Different Purposes

Frank Speiser frank at takkle.com
Mon Jun 4 22:10:09 GMT 2007


Hi All,

I am having a debate here with my friend, whom I'll call PHPGuy.

We're discussing scalability and using DBIC to handle multiple DBs. 
Eventually we're going to want to do LJ-style user clusters using the 
same idea here, but for now, I am saying that you can split the 
read-write and read-only traffic (and that it'll work just fine). So, if 
I was editing a profile, I'd use the read-write handle to get data, but 
otherwise if I were browsing it, I'd use the read-only. The read-write 
and read only would have different cache times for reads (as an example, 
0 seconds and 300 seconds). It'd be nice to do this within DBIC.

For some background, assuming I'm using Catalyst, here's one way to do it:

write DB:
$c->model('OneDB::Table1')->writefoo();

read DB pool:
$c->model('AnotherDB::Table2')->readfoo();

Is there a more generic way to do that same thing using DBIC, where I can maybe make a config file of tables and, if I match my SQL on one of those tables, it uses the read-only, but if it doesn't I use the read-write? I did this once with Class::DBI and DBD::Multiplex (which was easy enough), but it seems like there'd be an easier way to do this here. Has anyone done this yet?

If I can do this within DBIC, then I can get away without needing to know which DB handle I need when I call the routine, I can just set it up in a config file somewhere. 

Thanks,
Frank 









More information about the Dbix-class mailing list