checkit icon indicating copy to clipboard operation
checkit copied to clipboard

Unique constraint

Open jayceekay opened this issue 12 years ago • 5 comments

Maybe this is a silly question since it requires performing a query to validate it, but is there any way of implementing a unique validator? Or perhaps some standard workaround that I'm not aware of?

I'm also having a problem finding out where I could catch whatever error the mysql driver is returning when the insert fails the db level enforced unique constraint.

This is what I'm seeing when I attempt to insert something that fails the db level unique validator (username in this case; I reformatted the JSON for readability):

{
    "message": "{\"sql\":\"insert into `users` (`email`, `password`, `username`) 
     values (?, ?, ?)\",\"bindings\":
     [\"[email protected]\",\"$2a$10$NlzLA6AV0rsH0xcbhkcc4utr5lcs.h2rTahBXOhBheFcWpQlLJG1q\",\"j\"]}"
}

jayceekay avatar Oct 07 '13 02:10 jayceekay

Yeah, sorry I missed this. There should be, I'll keep this open just to make sure I document it... I've been working on finishing up some things here and getting a release out.

tgriesser avatar Oct 17 '13 13:10 tgriesser

+1 for baked in unique validation

activestylus avatar Mar 13 '14 04:03 activestylus

@tgriesser I understand that this might be considered outside of the scope of checkit. If so, do you have any recommendations for unique constraints and error/message handling outside of checkit? Or, is this just something you haven't gotten around to yet?

jarrodpayne avatar Sep 12 '14 05:09 jarrodpayne

@jpdesigndev @activestylus @jayceekay, could you please elaborate on each of your exact use cases for a unique constraint?

Do you mean a unique value in the object passed to the validator? (i.e. that value only exists once in all the properties on the object)

Or perhaps you mean something different?

In my own code I've been able to do custom messaging with a custom validation function by returning Promise.reject(new CustomError('My custom thing is invalid')) when there is an issue. Would something like this suit your needs?

Whoaa512 avatar Jun 13 '16 14:06 Whoaa512

that was 2.5 years ago and not relevant to me anymore. also cannot remember my use case. :)

jayceekay avatar Jun 13 '16 15:06 jayceekay