changeset¶
import "github.com/go-rel/changeset"
Overview¶
Package changeset used to cast and validate data before saving it to the database.
Package changeset used to cast and validate data before saving it to the database.
Variables¶
var CastAssocErrorMessage = "{field} is invalid"
var CastAssocRequiredMessage = "{field} is required"
var CastErrorMessage = "{field} is invalid"
var CheckConstraintMessage = "{field} is invalid"
var ForeignKeyConstraintMessage = "does not exist"
var PutAssocErrorMessage = "{field} is invalid"
var PutChangeErrorMessage = "{field} is invalid"
var PutDefaultErrorMessage = "{field} is invalid"
var UniqueConstraintMessage = "{field} has already been taken"
var ValidateExclusionErrorMessage = "{field} must not be any of {values}"
var ValidateInclusionErrorMessage = "{field} must be one of {values}"
var ValidateMaxErrorMessage = "{field} must be less than {max}"
var ValidateMinErrorMessage = "{field} must be more than {min}"
var ValidatePatternErrorMessage = "{field}'s format is invalid"
var ValidateRangeErrorMessage = "{field} must be between {min} and {max}"
var ValidateRegexpErrorMessage = "{field}'s format is invalid"
var ValidateRequiredErrorMessage = "{field} is required"
func AddError¶
func AddError(ch *Changeset, field string, message string)
ch := changeset.Cast(user, params, fields)
changeset.AddError(ch, "field", "error")
ch.Errors() // []errors.Error{{Field: "field", Message: "error"}}
func ApplyString¶
func ApplyString(ch *Changeset, field string, fn func(string) string)
func CastAssoc¶
func CastAssoc(ch *Changeset, field string, fn ChangeFunc, opts ...Option)
func CheckConstraint¶
func CheckConstraint(ch *Changeset, field string, opts ...Option)
func DeleteChange¶
func DeleteChange(ch *Changeset, field string)
func EscapeString¶
func EscapeString(ch *Changeset, fields ...string)
func ForeignKeyConstraint¶
func ForeignKeyConstraint(ch *Changeset, field string, opts ...Option)
func PutAssoc¶
func PutAssoc(ch *Changeset, field string, value interface{}, opts ...Option)
func PutChange¶
func PutChange(ch *Changeset, field string, value interface{}, opts ...Option)
func PutDefault¶
func PutDefault(ch *Changeset, field string, value interface{}, opts ...Option)
func UnescapeString¶
func UnescapeString(ch *Changeset, field string)
func UniqueConstraint¶
func UniqueConstraint(ch *Changeset, field string, opts ...Option)
func ValidateExclusion¶
func ValidateExclusion(ch *Changeset, field string, values []interface{}, opts ...Option)
func ValidateInclusion¶
func ValidateInclusion(ch *Changeset, field string, values []interface{}, opts ...Option)
func ValidateMax¶
func ValidateMax(ch *Changeset, field string, max int, opts ...Option)
func ValidateMin¶
func ValidateMin(ch *Changeset, field string, min int, opts ...Option)
func ValidatePattern¶
func ValidatePattern(ch *Changeset, field string, pattern string, opts ...Option)
func ValidateRange¶
func ValidateRange(ch *Changeset, field string, min int, max int, opts ...Option)
func ValidateRegexp¶
func ValidateRegexp(ch *Changeset, field string, exp *regexp.Regexp, opts ...Option)
func ValidateRequired¶
func ValidateRequired(ch *Changeset, fields []string, opts ...Option)
type ChangeFunc¶
type ChangeFunc func(interface{}, params.Params) *Changeset
type Changeset¶
type Changeset struct {
// contains filtered or unexported fields
}
func Cast¶
func Cast(data interface{}, params params.Params, fields []string, opts ...Option) *Changeset
func Change¶
func Change(schema interface{}, changes ...map[string]interface{}) *Changeset
func Convert¶
func Convert(data interface{}) *Changeset
func (*Changeset) Apply¶
func (c *Changeset) Apply(doc *rel.Document, mut *rel.Mutation)
func (Changeset) Changes¶
func (c Changeset) Changes() map[string]interface{}
func (Changeset) Constraints¶
func (c Changeset) Constraints() Constraints
func (Changeset) Error¶
func (c Changeset) Error() error
func (Changeset) Errors¶
func (c Changeset) Errors() []error
func (Changeset) Fetch¶
func (c Changeset) Fetch(field string) interface{}
func (Changeset) Get¶
func (c Changeset) Get(field string) interface{}
func (Changeset) Types¶
func (c Changeset) Types() map[string]reflect.Type
func (Changeset) Values¶
func (c Changeset) Values() map[string]interface{}
type Constraint¶
type Constraint struct {
Field string
Message string
Code int
Name string
Exact bool
Type rel.ConstraintType
}
type Constraints¶
type Constraints []Constraint
func (Constraints) GetError¶
func (constraints Constraints) GetError(err error) error
type Error¶
type Error struct {
Message string `json:"message"`
Field string `json:"field,omitempty"`
Code int `json:"code,omitempty"`
Err error `json:"-"`
}
func (Error) Error¶
func (e Error) Error() string
func (Error) Unwrap¶
func (e Error) Unwrap() error
type Option¶
type Option func(*Options)
func ChangeOnly¶
func ChangeOnly(changeOnly bool) Option
func Code¶
func Code(code int) Option
func EmptyValues¶
func EmptyValues(values ...interface{}) Option
func Exact¶
func Exact(exact bool) Option
func Message¶
func Message(message string) Option
func Name¶
func Name(name string) Option
func Required¶
func Required(required bool) Option
func SourceField¶
func SourceField(field string) Option
type Options¶
type Options struct {
// contains filtered or unexported fields
}
Last update: 2024-12-19