[Dbix-class] best way to cleanse / validate data
Eden Cardim
edencardim at gmail.com
Tue Jan 18 12:10:58 GMT 2011
>>>>> "Seth" == Seth Daniel <dbix-class at sethdaniel.org> writes:
Seth> I was mostly thinking of trivial cases. i.e. a simple check to verify
Seth> the column meets a certain pattern or is a certain type. Curiously, why
Seth> would I need to check for uniqueness? Every database I plan on using
Seth> does this for me (which isn't to say that every database DBIx::Class
Seth> supports does this).
Because databases do that transactionally, in quite a few cases you
don't want to wait for the full transaction to execute before validating
an individual field for uniqueness, specially when dealing with user
interfaces. It's also not trivial to figure out what exactly went wrong
with the transaction (for user feedback) without tightly coupling your
API to a specific schema and backend implementation.
Seth> It seemed to me the lowest level I could do this type of checking was
Seth> the accessor. This turned out to be incorrect. Certainly, doing the
Seth> checking at a higher level will work, but seems like a lot more effort
Seth> since I'd have to check the same columns over and over in different API
Seth> calls.
Don't use different API calls then, use a single API, validate there and
make all the other components talk to it. Depending on what you need,
even a simple method modifier like override/around applied to the
accessor can do the trick.
--
Eden Cardim
Software Engineer
Shadowcat Systems Ltd.
http://www.shadowcat.co.uk
http://blog.edencardim.com
More information about the DBIx-Class
mailing list