Re: [CDBI] CDBI Newbie Question

[prev] [thread] [next] [Date index for 2005/09/27]

From: Matt S Trout
Subject: Re: [CDBI] CDBI Newbie Question
Date: 16:48 on 27 Sep 2005
On Tue, Sep 27, 2005 at 05:26:00PM +0100, Steven Mackenzie wrote:
> Hello,
> 
> I'm new to Perl (and to CDBI!), I hope someone can spare a minute to
> help me with a tangentially relevant question ... or point me in the
> right direction to ask or read more!

Ok.

http://wiki.class-dbi.com/ is a good one.

You also may wish to google up DBIx::Class, Tangram, Rose::DB::Object and
possibly Alzabo as well and have a look at them as alternatives (although
given I'm a long-time CDBI user as well as DBIx::Class project founder,
I'll avoid opining whether to switch to any of them :)

> I have written some test code to talk to a SQLite DB file and read data
> in to it via classes derived from Class::DBI. My test script worked
> fine, so I've factored out my DB access code, and packaged the classes
> for each table in to perl modules (.pm files).
> 
> Is that the normal thing to do?

Yep. Very much best practice in my experience.

> Because I'm starting a Big Project, I'm trying to keep my modules tidy,
> and have defined a hierarchy, with all my modules below ANPerl/; for
> example, one of my DB table classes is
> ANPerl::AnalysisFramework::ResourceStore::Metadata::DBDiscoverySetResources
>
> Unfortunately now in my client code I have lines like
>  $current_dsr_row =
> ANPerl::AnalysisFramework::ResourceStore::Metadata::DBDiscoverySetResources->create(
> 
>       {RetrievalUrl => $retrieval_url} );
> 
> That's a lot of typing! Is there any way to say that I'm using all the
> modules in the path ANPerl::AnalysisFramework::ResourceStore::Metadata?
> 
> Then I could just write
>   $current_dsr_row = DBDiscoverySetResources->create( {RetrievalUrl =>
> $retrieval_url} );

No, but there's an easy enough way to do it -

sub table { return "ANPerl::AnalysisFramework::ResourceStore::Metadata::$_[0]"; };

my $current_dsr_row = table('DBDiscoverySetResources')->create(...);

You could also have a look at Class::DBI::Factory, which is maybe overkill
but does assorted useful other things as well.

        -- 
             Matt S Trout       Specialists in perl consulting, web development, and
  Technical Director    UNIX/Linux systems architecture and automation. Mail
Shadowcat Systems Ltd.  mst (at) shadowcatsystems.co.uk for more information

 + Help us build a better perl ORM: http://dbix-class.shadowcatsystems.co.uk/ +

_______________________________________________
ClassDBI mailing list
ClassDBI@xxxxx.xxxxxxxxxxxxxxxx.xxx
http://lists.digitalcraftsmen.net/mailman/listinfo/classdbi

[CDBI] CDBI Newbie Question
Steven Mackenzie 16:26 on 27 Sep 2005

Re: [CDBI] CDBI Newbie Question
Matt S Trout 16:48 on 27 Sep 2005

Re: [CDBI] CDBI Newbie Question
Steven Mackenzie 17:44 on 27 Sep 2005

Re: [CDBI] CDBI Newbie Question
Bill Moseley 16:52 on 27 Sep 2005

Re: [CDBI] CDBI Newbie Question
Kingsley Kerce 16:55 on 27 Sep 2005

Re: [CDBI] CDBI Newbie Question
Steven Mackenzie 18:17 on 27 Sep 2005

Re: [CDBI] CDBI Newbie Question
Jay Strauss 02:02 on 28 Sep 2005

Re: [CDBI] CDBI Newbie Question
Todd W 02:21 on 28 Sep 2005

Re: [CDBI] CDBI Newbie Question
Steven Mackenzie 07:32 on 28 Sep 2005

Generated at 10:29 on 10 Oct 2005 by mariachi v0.52