[Dbix-class] A problem with Postgres schemas

John Napiorkowski jjn1056 at yahoo.com
Thu Dec 28 21:14:51 GMT 2006


--- Kevin Esteb <kesteb at wsipc.org> wrote:

> I new to DBIx::Class, so please bear with me. 
> 
> I am running RHEL4 and have a postgres database with
> a schema named
> "analog". The DBIx::Class modules are the latest and
> greatest from CPAN,
> so is the DBD and the DBI for postgres. When I run
> the below code, I get
> this error:
> 
> DBIx::Class::Schema::resultset(): Can't find source
> for analog.master at
> test9.pl line 28
> 
> What is the proper way to access another database
> schema within
> postgres.
> 
> Thanks
> 
> 
> package Test::Schema;
> use base qw/ DBIx::Class::Schema /;
> 
> __PACKAGE__->load_classes();
> 
> 1;
> 
> package Test::Schema::Master;
> use base qw/ DBIx::Class /;
> 
> __PACKAGE__->load_components(qw/ PK::Auto Core /);
> __PACKAGE__->table('analog.master');
> __PACKAGE__->add_columns(qw/ hostname datetime did
> /);
> __PACKAGE__->set_primary_key('hostname');
> 
> 1;
> 
> package Test;
> 
>     my $dsn = 'dbi:Pg:dbname=monitor';
>     my $username = 'postgres';
>     my $password = '';
>     my $params = {RaiseError => 1, AutoCommit => 0};
> 
>     eval {
> 
>         my $schema = Test::Schema->connect($dsn,
> $username, $password,
> $params);
>         my @masters =
> $schema->resultset('analog.master')->search();
> 
>         foreach my $master (@masters) {
> 
>            print "$master->hostname,
> $master->datetime, $master->did\n";
> 
>        }
> 
>    }; if ($@) { print "$@\n"; }
> 
> 1;

I also use Postgres with schemas; if your schema name
is not the default schema you need to use:

__PACKAGE__->table('analog.master');

which you did, but you don't do 'schema.table' for the
resultset:

$schema->resultset('analog.master')->search()

because the resultset is based on the class:

package Test::Schema::Master;

Try:

$schema->resultset('Master')->search();

and if everything else is right it should work.  If
not let me know, I can share with you my setup.

Actually it's just convention to have the Schema name
and the table name the same, you could do otherwise
from what I understand (although I haven't tried it :)

--John

> 
> _______________________________________________
> List:
>
http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
> Wiki: http://dbix-class.shadowcatsystems.co.uk/
> IRC: irc.perl.org#dbix-class
> SVN:
>
http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
> Searchable Archive:
>
http://www.mail-archive.com/dbix-class@lists.rawmode.org/
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 



More information about the Dbix-class mailing list