Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Catalyst and DBI

by Solo (Deacon)
on Aug 25, 2011 at 09:28 UTC ( #922305=note: print w/replies, xml ) Need Help??


in reply to Re^2: Catalyst and DBI
in thread Catalyst and DBI

I use DBI, because I must write live queries without any ORM... But now every model has it's own connection...

Do you need more than one DBI model per database, and if so, why?

--Solo

--
You said you wanted to be around when I made a mistake; well, this could be it, sweetheart.

Replies are listed 'Best First'.
Re: Catalyst and DBI
by brainbuz (Novice) on Sep 08, 2011 at 15:16 UTC

    I've been working on some documentation for dbi models.

    • http://brainbuz.org/techinfo/Catalyst-Model-Simple-Tutorial.html
    • or
    • https://github.com/brainbuz/Catalyst--Model--Simple--Tutorial

    You would create a single model to connect to each database. Then you would create submodels for each group of methods, I frequently group them by table.

    # Parent MODEL package BoPeep::Model::BoPeep; use strict; use warnings; use DBIx::Simple ; use parent 'Catalyst::Model::DBI'; __PACKAGE__->config( dsn => BoPeep->config->{dsn} , user => BoPeep->config->{user} , password => BoPeep->config->{password} , ); use Moose ; #use Moose immediately before calling #on Moose to extend the object has db=>( is =>'ro', isa=>'DBIx::Simple', lazy_build=> 1, # If we don't want to handle all dbis methods, # specify those that we want. # handles=> [qw/query flat /], ); sub _build_db { my $self = shift ; return DBIx::Simple->connect($self->dbh); } ; # Child Model package BoPeep::Model::BoPeep::Flock; use Moose; use BoPeep; use namespace::autoclean; extends 'BoPeep::Model::BoPeep'; sub List { my $self = shift ; my $db = $self->db ; my @sheep = $db->query('SELECT * FROM flock')->flat ; return @sheep ; } __PACKAGE__->meta->make_immutable( inline_constructor => 0 ); 1;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://922305]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2021-08-05 02:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?