Hello,

This question has been asked a couple of times on the list, and I have found yet another solution to it, but I would like to hear if maybe I'm doing something wrong, or I will suffer serious pain by doing it my way :)

We have an app that will connect to one database or another depending on the logged in user.

My solution:

package App::Model::DB;

use strict;
use base 'Catalyst::Model::DBIC::Schema';
...
sub ACCEPT_CONTEXT {
    my ($self, $c) = @_;

    my $user_db = $c->lookup_the_users_db();
    $self->config->{'connect_info'}->[0] =~ s/#DATABASE#/$user_db/;
    $self->schema->connection(@{$self->config->{'connect_info'}});

    return $self;
}


1;

I've done the same with Catalyst::Model::DBI:

package App::Model::AnotherDB;

use strict;
use base 'Catalyst::Model::DBI';

sub ACCEPT_CONTEXT {
    my ($self, $c) = @_;

    my $user_db = $c->lookup_the_users_db();
    $self->{'dsn'} =~ s/#DATABASE#/$user_db/;

    return $self;
}

1;

And the two seem to be working OK, but I'm worried about what will happen when we fire it up in a FastCGI environment (I suspect the connection to user1's database will be kept live, and the next user will get the connection to it). Am I right? Any pointers?

Does this way of using the models trigger any warning lights to Catalyst gurus?

Thanks in advance,

Jose Luis Martinez
[EMAIL PROTECTED]

_______________________________________________
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/

Reply via email to