[Catalyst] DBI Models Question.

Hans Staugaard h.staugaard at tweakker.com
Fri Jun 10 06:15:51 GMT 2011


Hi John

I think I would just add something like this to the model:

    has db => (
        is =>'ro',
        isa => 'DBIx::Simple',
        lazy_build=> 1,
        handles => [qw/query select insert delete/], # Etc.
    );

    sub _build_db {
        my $self = shift;
        return DBIx::Simple->connect($self->dbh);
    }

then you should be able to use $self->db, $self->query etc in your subs.

Regards, Hans

On 2011-06-10 02:39, John Karr wrote:
>
> I've been dabbling with catalyst for a while and working with
> Model::DBI. There are a few issues that I haven't figured out to my
> satisfaction.
>
> loading the dbi connection strings from myapp.conf
>
> extending the dbi model with DBIx::Simple. My current method is to
> create a new dbixsimple object from $self->dbh in every subroutine, I
> would like to get to a point where this is set up in setup of each dbi
> model and accessible in a manner like either: my $db = $self->db or
> $self->do_some_dbixsimple_method( @arguments ).
>
> I'd also be happy to hear some views on:
> pointers on good coding for dbi models -- the balance between
> reusability and not ending up with a method in your model for every
> possible query.
>
> =====
>
> The discussion I am attempting to start is about DBI models and not
> the merits of ORM vs DBI, but about doing DBI models well.
>
>
> _______________________________________________
> List: Catalyst at 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/
>



More information about the Catalyst mailing list