[Dbix-class] best way to cleanse / validate data
Seth Daniel
dbix-class at sethdaniel.org
Mon Jan 17 18:26:18 GMT 2011
On Mon, Jan 17, 2011 at 09:19:13AM -0200, Eden Cardim wrote:
> >>>>> "Seth" == Seth Daniel <dbix-class at sethdaniel.org> writes:
>
> Seth> Hi, I was wondering what is the preferred way to cleanse and
> Seth> validate incoming data when using DBIx::Class?
[...snip...]
>
> Personally, I've found that a generic validation solution is only
> adequate for the most trivial cases, like constraining an int to a
> certain range of values or checking for email well-formedness. For
> anything more complex than that, like checking for uniqueness or
> building a list of the possible values that are allowed for a certain
> field, I'd say you're better off writing your own logic, YMMV.
I was mostly thinking of trivial cases. i.e. a simple check to verify
the column meets a certain pattern or is a certain type. Curiously, why
would I need to check for uniqueness? Every database I plan on using
does this for me (which isn't to say that every database DBIx::Class
supports does this).
> Seth> So beyond data validation I'd like any opinion on the *proper* way to
> Seth> cleanse data before it gets placed in the database. Mostly I'm just
> Seth> looking for a way to make certain varchar columns are all lower case.
> Seth> I'm also looking for a good way to validate the incoming data for
> Seth> certain columns. Again, I was hoping using MooseColumns would allow me
> Seth> to use Moose's type system, but since the accessors don't get called for
> Seth> some common DBIx::Class methods the usefulness is less than I had hoped.
>
> How about wrapping the relevant API calls with Params::Validate?
It seemed to me the lowest level I could do this type of checking was
the accessor. This turned out to be incorrect. Certainly, doing the
checking at a higher level will work, but seems like a lot more effort
since I'd have to check the same columns over and over in different API
calls.
--
seth /\ sethdaniel.org
More information about the DBIx-Class
mailing list