Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Looking for DBIx::Class tutorials and examples

by morgon (Priest)
on Apr 23, 2009 at 16:18 UTC ( [id://759578]=perlquestion: print w/replies, xml ) Need Help??

morgon has asked for the wisdom of the Perl Monks concerning the following question:

Hi

I find (my fault probably) the documentation that comes with DBIx::Class not very helpful.

Can someone point me to some tutorials or example-code that illustrate some not totally trivial usage (the CD-Shop example is too simple for me).

Many thanks!

  • Comment on Looking for DBIx::Class tutorials and examples

Replies are listed 'Best First'.
Re: Looking for DBIx::Class tutorials and examples
by Your Mother (Archbishop) on Apr 23, 2009 at 17:02 UTC

    I don't have any good tutorials or examples to link right now but I wanted to say it's not your fault. DBIC covers some complicated ground and the docs miss many edge cases, gloss or skip some things which are simple after you understand them, some unusual points of functionality are undocumented or documented three modules away in places like SQL::Abstract or SQL::Translator, et cetera. Since we're on the topic, reading the internals to learn more is quite difficult. So, if someone recommends that, you might keep asking. :)

    The DBIC mailing list is friendly and some of the core devs hang out on the irc channel often. So, if you can break your hurdles down to manageable bits, you can definitely get help and sometimes spark doc patches doing so. You can ask here too, of course. If you want to write a tutorial as you learn, it's a great time; it could be part of: The Enlightened Perl Iron Man Competition. Most DBIC power users forget the things they needed to learn to get into it.

    Update: I forgot half the point: It's difficult but I have found it entirely worth it. With DBIC I can do things like develop DB schemas on the fly because my code will simply adjust itself to whatever harebrained table/relationship changes I want to try out. Inflation, versioning, auto-deployment, result set extension and chaining, and more have saved me at least 10x the time I put into picking up DBIC and the ratio only improves over time. So, stick with it. :)

    Update 2: I found this really helpful dbix-masterclass.xul though it's not an entry level "talk."

    Update 2017-04-23: linked module names.

      Ok, thanks a lot, I'll play with it a little more but I am getting frustrated...

      Here's e.g. one problem I have:

      I have two classes/tables with a one-to-many relationship.

      So in the one I do

      # in SMU::Bubba __PACKAGE__->has_many( hubbas => 'SMU::Hubba' );
      In the other I do:
      # in SMU::Hubba __PACKAGE__->belongs_to( bubba => 'SMU::Bubba' );
      So now I can navigate from a Bubba-instance to a Hubba-instance like this:
      my $hubba = $bubba->bubbas->find($id);
      But now when I want to navigate back from the Hubba to the Bubba via
      $hubba->bubba
      I can do that and it gives me a Bubba-instance, but I am getting a different instance of the class (describing the same row) which is causing me problems as I want to be able to walk the whole graph up and down and then do one update.

      Maybe I really do it all in plain DBI...

        I think this line is supposed to be hubbas, not bubbas, just to clarify-

        $hubba = $bubba->hubbas->find($id);

        That's a bit odd way to do it. hubbas called on a bubba is going to return the list of the hubbas that belong to it. I didn't even realize your syntax would work (calling a method on the hubbas call). I can't test it now but it's probably because the context returns an iterator instead of an object list and the iterator will allow the find call.

        You probably want, should be using, the search_related method. $hubba->bubba returns the object representing the result/row of that bubba. It's not a resultset and I don't think context manipulation, like the hubbas call can change that.

        About DBI... DBI is great! DBIC is built on it and its various engines. That said, DBIC buys you 100 things DBI doesn't and they are the things that most devs end up rolling themselves in some form or another and doing 1) badly, 2) without tests, 3) in a dead-end way, 4) without public release, 4) buggy, 5) etc. I have a rant brewing for AM below. Don't know if I'll bother tonight but that kind of thinking is what dooms software projects that end up growing to be miserable dung heaps for the devs who inherit them; c.f., me.

Re: Looking for DBIx::Class tutorials and examples
by castaway (Parson) on Apr 25, 2009 at 21:31 UTC
      Hey,

      http://desert-island.me.uk seems to be unavailable since a couple of days. It's very sad because your documentation was very helpful! Can we imagine it will be back soon?

      Thanx for your work.
Re: Looking for DBIx::Class tutorials and examples
by aramisf (Beadle) on Feb 22, 2015 at 14:47 UTC

    Meta CPAN is a very good reference

    I was wondering why so few answers here on the monastery are citing new documentation sites. Some of my last search results (which includes web frameworks) are a little dated.

      The default shortcut for linking documentation here looks like [mod://DBIx::Class] and creates links to search.cpan.org. I agree that metacpan is today a superior resource. There have been debates about switching the programmatic linking shortcut but so far it’s not looking like a change is coming. You can always hard code your HTML anchors to where you like (not as convenient or as wise—the day for programmatic change will probably arrive eventually).

      (update: fixed double negative, thanks LanX.)

        You can use [metamod://] instead of [mod://], and similarly for [metacpan://].
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
        > update: fixed double negative, thanks LanX.

        Think positive! ;-)

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)

        PS: Je suis Charlie!

Re: Looking for DBIx::Class tutorials and examples
by Anonymous Monk on Apr 23, 2009 at 18:02 UTC
    Here's a tutorial:

    Don't use it. DBI.pm will do everything you need and I would bet 5 dollars that you haven't researched DBI.pm fully. But I don't have 5 dollars :(

      I would bet 5 dollars that you haven't researched DBI.pm fully
      In fact I haven't. I am constantly learning new things about it even though I have used it for 10 years or so with Oracle, Sybase, DB2 and MySQL.

      But when I ask about DBIx::Class I mean DBIx::Class.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-19 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found