tgriesser / checkit

simple, flexible validations for node and the browser
MIT License
223 stars 53 forks source link

Unique constraint #1

Open jayceekay opened 11 years ago

jayceekay commented 11 years ago

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\":
     [\"j@j.com\",\"$2a$10$NlzLA6AV0rsH0xcbhkcc4utr5lcs.h2rTahBXOhBheFcWpQlLJG1q\",\"j\"]}"
}
tgriesser commented 11 years ago

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.

activestylus commented 10 years ago

+1 for baked in unique validation

paynecodes commented 10 years ago

@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?

Whoaa512 commented 8 years ago

@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?

jayceekay commented 8 years ago

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