FAQ
Hello!
I came from rose::db background so I wonder if there is way

to avoid this to in using a
my $other_schema = My::Schema->connect( $dsn, $user, $password, $attrs );

in rose::db it hides all connection details in DB.pm so I don't need
to worry about connection details each time I access a table.
I just need to use My::TableName to use the table.

Thanks!
Jim.

Search Discussions

  • Eden Cardim at Feb 20, 2011 at 2:16 pm
    "Jim" == Jim Green writes:
    Jim> Hello!
    Jim> I came from rose::db background so I wonder if there is way

    Jim> to avoid this to in using a
    Jim> my $other_schema = My::Schema->connect( $dsn, $user, $password, $attrs );

    Jim> in rose::db it hides all connection details in DB.pm so I don't need
    Jim> to worry about connection details each time I access a table.
    Jim> I just need to use My::TableName to use the table.

    Why don't you keep a pre-connected $schema object within the scope of
    your table accesses instead? DBIC will automatically reconnect if the
    connection is dropped between table accesses.

    In any case, does

    --8<---------------cut here---------------start------------->8---
    package My::Schema;

    [...]

    sub autoconnect { shift->connect($dsn, $user, $password, $attrs) }

    [...]

    my $schema = My::Schema->autoconnect;
    --8<---------------cut here---------------end--------------->8---

    solve the problem for you? I'd still recommend the former aproach.

    --
    Eden Cardim
    Software Engineer
    Shadowcat Systems Ltd.
    http://www.shadowcat.co.uk
    http://blog.edencardim.com
  • Jim Green at Feb 23, 2011 at 6:57 pm

    Why don't you keep a pre-connected $schema object within the scope of
    your table accesses instead? DBIC will automatically reconnect if the
    connection is dropped between table accesses.
    lets say I have
    __PACKAGE__->connection(connection details) in the Schema.pm
    when I want to use a certain table I still need to


    my $schema = My::Schema->connect();

    in my application code.

    I don't think it is smart enough to have to do this each time I need to
    access a table.

    I want something as simple as
    my $rs = $schema->resultset(tablename),

    everything else I hope dbic can conceal it.

    Thanks!
    Jim

    --
    View this message in context: http://dbix-class.35028.n2.nabble.com/question-about-connect-from-manual-tp6045074p6057443.html
    Sent from the DBIx-Class mailing list archive at Nabble.com.
  • Eden Cardim at Feb 24, 2011 at 2:47 pm
    "Jim" == Jim Green writes:
    Jim> lets say I have
    __PACKAGE__-> connection(connection details) in the Schema.pm
    Jim> when I want to use a certain table I still need to


    Jim> my $schema = My::Schema->connect();

    Jim> in my application code.

    Jim> I don't think it is smart enough to have to do this each time I need to
    Jim> access a table.

    Jim> I want something as simple as
    Jim> my $rs = $schema->resultset(tablename),

    What's keeping you from doing that? As long as you hold on to the
    $schema object, it'll be connected, you don't have to connect once for
    every query.

    --
    Eden Cardim
    Software Engineer
    Shadowcat Systems Ltd.
    http://www.shadowcat.co.uk
    http://blog.edencardim.com

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdbix-class @
categoriesperl, catalyst
postedFeb 20, '11 at 5:39a
activeFeb 24, '11 at 2:47p
posts4
users2
websitedbix-class.org
irc#dbix-class

2 users in discussion

Eden Cardim: 2 posts Jim Green: 2 posts

People

Translate

site design / logo © 2021 Grokbase