Documentation
¶
Overview ¶
Package gormrules provides the database-backed exists and not_exists rules for the validator, implemented as FallibleRule over a *gorm.DB. Expressions name a table and one or more columns, for example "not_exists:users,phone,email": the value matches when any listed column equals it. Absent and zero values are skipped so presence stays the job of required, and a query failure surfaces as *validator.RuleError rather than as a field failure.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNilDB = errors.New("gormrules: nil database")
ErrNilDB is returned by New when db is nil.
Functions ¶
Types ¶
type Exists ¶
type Exists struct {
// contains filtered or unexported fields
}
Exists validates that a value exists in one of the given table columns. It is registered by New and exported so a custom Validator can reuse it through validator.WithFallibleRules.
func (*Exists) CheckArgs ¶ added in v0.1.1
CheckArgs rejects, at compile time, an expression without a table and at least one column, or with a name that is not a plain SQL identifier.
type NotExists ¶
type NotExists struct {
// contains filtered or unexported fields
}
NotExists validates that a value does not exist in any of the given table columns, the usual uniqueness check on registration forms. It is registered by New and exported so a custom Validator can reuse it through validator.WithFallibleRules.
func (*NotExists) CheckArgs ¶ added in v0.1.1
CheckArgs rejects, at compile time, an expression without a table and at least one column, or with a name that is not a plain SQL identifier.
func (*NotExists) Message ¶
Message is the fallback template; override it via validator.WithMessages.