Re: [CDBI] using different DSNs for reads/writes
Brian Duggan <bduggan-ID3/[email protected]> Wed, 19 Dec 2007 20:50:31 -0500
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday, December 19, Michael G Schwern wrote:
> I could have sworn there were separate "read" vs "write" database handles
> because I've dealt with this sort of problem before both to handle your issue
> with master/slave databases and also to just have a separate "reader" database
> user with lowered permissions to tighten security. But I can't seem to find it.
To handle the latter case in a maypole application, this is what I do :
__PACKAGE__->Ima::DBI::set_db(
Read => # ... read params
);
__PACKAGE__->Ima::DBI::set_db(
Write => # ... write params
);
__PACKAGE__->mk_classdata(useWriteDBH => 0); # Toggled during authorization phase to determine access.
Then, just
sub db_Main {
my $class = shift;
return $class->useWriteDBH ? $class->db_Write(@_) : $class->db_Read(@_);
}
Brian