-
Notifications
You must be signed in to change notification settings - Fork 4
/
notexists.go
24 lines (20 loc) · 742 Bytes
/
notexists.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package govalidator
const (
// NotExists represents rule name which will be used to find the default error message.
NotExists = "notExists"
// NotExistsMsg is default error message format for fields with with NotExists validation rule.
NotExistsMsg = "%s already exists"
)
// NotExists checks if the given value doesn't exist in the desired table.
//
// Example:
//
// v := validator.New()
// v.NotExists(42, "users", "id", "user_id", "user with id 42 already exists.")
// if v.IsFailed() {
// fmt.Printf("validation errors: %#v\n", v.Errors())
// }
func (v Validator) NotExists(value any, table, column, field, msg string) Validator {
v.check(!v.repo.Exists(value, table, column), field, v.msg(NotExists, msg, field))
return v
}