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

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


Rob Kinyon schrieb:
> On Tue, Jul 21, 2009 at 13:35, Ulrich Kautz<uk.lists at fortrabbit.de>
> wrote:
>>> 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 ..
> 
> Frankly, I am of the opinion that if you have DataValidation as one
> of your components, any of your columns with a type should at least 
> validate against that type. This would seriously help with SQLite 
> usage.
> 
>>> 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 ?
> 
> That works.
> 
>>> 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.
> 
> Bah. Autoload that crap based on the storage_type I already told DBIC
>  about in my DSN. Don't make me hardcode anything.
> 
> Rob
> 

Alright then, i'll look into it at the weekend. The validation via DBMS determiniation looks like a goode idea. Thanks.

Ulrich



More information about the DBIx-Class mailing list