in reply to Class::DBI -- does it get any easier?

To make it even easier, take a look at Class::DBI::Loader and Class::DBI::Loader::Relationship.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re: Class::DBI -- does it get any easier?

Replies are listed 'Best First'.
Re^2: Class::DBI -- does it get any easier?
by Corion (Patriarch) on Nov 12, 2004 at 09:45 UTC

    While I can recommend Class::DBI::Loader, I can only discourage people from using Class::DBI::Loader::Relationship, which I consider underdocumented and over-hyped. It is/was nice and convincing for Simons live demonstration of how to create a web frontend for a database in under 20 lines of code, but using english as a configuration language for your relationships is really error prone. The error messages or diagnostics (not) output by cdbi:l:r don't help either, and unless you have taken a long look at the source code, it's not easy to modify the examples to suit your actual situation. A more formal syntax would help here and remove the heavy dependency on a good and judicous choice of words made by the program author while still preserving the wanted clarity.

    The module relies on the very simple-minded yet totally undocumented assumption that all phrases will be of the form single-noun verb (a|many) noun - once you glean this from the source code, you can start using it, but the time is better invested in some less magic method of setting things up.

    Adding to the situation is, that the module is not maintained anymore, and if I stepped up as maintainer of it, I would mainly depreciate the use of the module and replace it by something with a more formal syntax:

    brewery 1:n beer # "a brewery produces many beers" beer m:n(handpump) pub # "a pub has beers on handpumps"

      I find the module useful, tho' I recognise many of the shortcomings that you mention. I've asked to take over maintenance of the module, and if I get it I'll certainly be interested in any suggestions for improvement.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

Re^2: Class::DBI -- does it get any easier?
by drewbie (Chaplain) on Nov 12, 2004 at 15:35 UTC
    Regarding Class::DBI::Loader, I've briefly looked at it before and thought it looked very handy (especially in introducing Class::DBI for a large number of existing tables). But does this work if you need custom logic in the module in addition to the basic column/relationship definitions? Can you still define My::TableName as a package, add the logic there, and have perl see it automagically? It's still unclear after reading the docs and code.
      as i understand it ( and i'm not an expert on it by any means ), there are easy ways to override behaviours if needed, some initialization hooks, etc. if all else were to fail, nothing stops one from going back to 'basic' SQL for some things.
        I think I didn't properly state my question. Let's say I want to add business logic to the module, say a login() method. This method would take some input and then set/clear columns as appropriate such that a user is now logged in. It might even call methods in other modules. So constraints, triggers, etc would not accomplish this.

        I assume others are doing the same.

      Yes. I often have packages that look something like this:

      use Class::DBI::Loader; my $loader = Class::DBI::Loader->new( dsn => 'dbi:mysql:dbname', user => 'user', password => 'p455w0rd', namespace => 'MyApp', ); # MyObject is one of the tables in the database package MyApp::MyObject; # define various methods on that class 1;
      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg

Re^2: Class::DBI -- does it get any easier?
by geektron (Curate) on Nov 12, 2004 at 17:00 UTC