[Dbix-class] DBIx::Class, another data validation approach

Ulrich Kautz uk.lists at fortrabbit.de
Tue Jul 21 17:35:17 GMT 2009


Rob Kinyon schrieb:
> On Tue, Jul 21, 2009 at 11:51, Andy Armstrong<andy at hexten.net> wrote:
> 
>> On 21 Jul 2009, at 16:29, Ulrich Kautz wrote:
>>> DBIx::Class::DataValidator
>>> 
>>> PRO: + Multiple mergable validators supported for multiple
>>> contexts at runtime (create, update, customs.. ) + Brings columns
>>> and validation together at definition time. + Better DRY support
>>> via named validation methods and column classes (inheritable) +
>>> Deflate / inflate aware
>>> 
>>> CONTRA: - More complex usage, consists of two modules (ResultSet
>>> and Component), more settings (configuration) makes it less
>>> lighweight - Bound to Data::FormValidator


Thanks for the input. Now i have some questions ;)

> 
> First off, I think this is better than DBIC::Validation. It is a 
> better fit to the ResultSet/Row separation that DBIC is all about.
> 
> That said, there's a few things that I'd like to see be done: 1) With
> one setting, I should be able to turn on validation for all my 
> columns that have a type set for them. So, if I have a column that is
>  an integer, that should just turn on for me.

Ok, on which level ? For a single model, for all models with columns of a certain type globaly (see 3) or at runtime (eg before the actual update/create.. something like $object->validates( $data_ref, { exclude_types => [ qw/ integer / ] } ) ?
What use-cases can you imagine for this (for my better understanding of the requirements) ? For my use, the decision which validator(s) or none at all to use was sufficient, so far, but that doesnt mean anything ..

> 2) I should be able to chain validations. So, something like 
> "validation => [ 'foo', 'bar' ]". Look at how Moose does this.

I'm not quite sure wheter this is not already implemented. Right now, you can provide multiple validators for (update|update_all|create)_validated and the validates method itself. These will by applied one after another, thus chained. Eg:
$object->validates( $data_ref, qw/ validator1 validator2 / );
That's what you meant, or am i missing the point ?

> 3) Different DBMSes have different types. So, maybe producer-specific
>  validations would be helpful (q.v. #1).

Sounds very intersting. I could imagine validation-set-modules, one for every DBMS, like DBIx::Class::DataValidator::MySQLTypes. Then one should be able to enable/disable a subset of validation types.. eg
__PACKAGE__->mysql_validation_enable( qw/ :all / );
__PACKAGE__->mysql_validation_disable( qw/ date datetime / );
If you do this in your super-model (from which all inherit) this would apply globally.
If you switch the DBMS now, you simple load another module like DBIx::Class::DataValidator::PostgresTypes or so and all the special columns for this DBMS will be validated.

> This is also starting to get very very close to custom types. There's
>  been discussion of this for 0.09. I think getting you involved would
>  be very helpful.

Sure, if i can. 


Ulrich



More information about the DBIx-Class mailing list