In 2003 I developed a utility to generate Data::FormValidator profiles
dynamically from a database schema. Releasing that project was stalled
at the time because the DBD::Pg driver didn't have adequate meta data
support. I helped to patch DBD::Pg for that, but apparently never got
around to releasing the tool.

Now I found that since I upgraded from PostgreSQL 7.1 to 8.0, many of
the tests don't pass anymore.

Still, the concept seems useful enough that I'm now releasing the code I
have, in its broken state. 

It's here:
http://mark.stosberg.com/dfv/Data-FormValidator-Util-Generator-0.03.tar.gz

Some of the docs are below. 

If people express some interest in patching this, I can help development
along by setting up a darcs repo and making releases to CPAN.

I'm also open to ideas for shorter names, or other API changes

Enjoy. 

    Mark


###################


NAME
    Data::FormValidator::Util::Generator - Generate FormValidator Profiles

SYNOPSIS
      use Data::FormValidator::Util::Generator;
      my $profile = generate_profile($dbh,$table);

      use Data::Dumper;
      print Dumper $profile;

DESCRIPTION
     my $profile = generate_profile($DBH,$table);

    This routine takes a database handle and table name as input and returns
    a Data::FormValidator profile based on the constraints found in the
    database. Currently the following details are used to create the
    profile.

    required and optional
    Fields defined as "not null" will be marked as required. Otherwise
    they will be optional.

    maximum length
    For text fields, a constraint will be added to insure that the text
    does not exceed the allowed length in the database

    type checking
    boolean, and numeric types will be checked that their input looks
    reasonable for that type.

    For date, time, and timestamp fields, a constraint will be generated
    to verify that the input will be in a format that Postgres accepts.

    basic constraint parsing
    One basic constraint is current recognized and transformed. If a
    field must match one of a predetermined set of values, it will be
    tranformed into an appropriate regular expression. In Postgres, this
    constraint may look like this:

     ((approval_state = \'needs_approval\'::"varchar") OR (approval_state = 
\'approved\'::"varchar"))

    That will transformed into:

     approval_state => qr/^needs_approval|approved$/


--
 . . . . . . . . . . . . . . . . . . . . . . . . . . . 
   Mark Stosberg            Principal Developer  
   [EMAIL PROTECTED]     Summersault, LLC     
   765-939-9301 ext 202     database driven websites
 . . . . . http://www.summersault.com/ . . . . . . . .

Reply via email to