mirror of
https://github.com/astaxie/beego.git
synced 2024-11-16 16:10:55 +00:00
92 lines
1.6 KiB
Go
92 lines
1.6 KiB
Go
package orm
|
|
|
|
import ()
|
|
|
|
type fieldError struct {
|
|
name string
|
|
err error
|
|
}
|
|
|
|
func (f *fieldError) Name() string {
|
|
return f.name
|
|
}
|
|
|
|
func (f *fieldError) Error() error {
|
|
return f.err
|
|
}
|
|
|
|
func NewFieldError(name string, err error) IFieldError {
|
|
return &fieldError{name, err}
|
|
}
|
|
|
|
// non cleaned field errors
|
|
type fieldErrors struct {
|
|
errors map[string]IFieldError
|
|
errorList []IFieldError
|
|
}
|
|
|
|
func (fe *fieldErrors) Get(name string) IFieldError {
|
|
return fe.errors[name]
|
|
}
|
|
|
|
func (fe *fieldErrors) Set(name string, value IFieldError) {
|
|
fe.errors[name] = value
|
|
}
|
|
|
|
func (fe *fieldErrors) List() []IFieldError {
|
|
return fe.errorList
|
|
}
|
|
|
|
func NewFieldErrors() IFieldErrors {
|
|
return &fieldErrors{errors: make(map[string]IFieldError)}
|
|
}
|
|
|
|
type Manager struct {
|
|
ins Modeler
|
|
inited bool
|
|
}
|
|
|
|
// func (m *Manager) init(model reflect.Value) {
|
|
// elm := model.Elem()
|
|
// for i := 0; i < elm.NumField(); i++ {
|
|
// field := elm.Field(i)
|
|
// if _, ok := field.Interface().(Fielder); ok && field.CanSet() {
|
|
// if field.Elem().Kind() != reflect.Struct {
|
|
// field.Set(reflect.New(field.Type().Elem()))
|
|
// }
|
|
// }
|
|
// }
|
|
// }
|
|
|
|
func (m *Manager) Init(model Modeler, args ...interface{}) Modeler {
|
|
if m.inited {
|
|
return m.ins
|
|
}
|
|
m.inited = true
|
|
m.ins = model
|
|
skipInitial := false
|
|
if len(args) > 0 {
|
|
if b, ok := args[0].(bool); ok && b {
|
|
skipInitial = true
|
|
}
|
|
}
|
|
_ = skipInitial
|
|
return model
|
|
}
|
|
|
|
func (m *Manager) IsInited() bool {
|
|
return m.inited
|
|
}
|
|
|
|
func (m *Manager) Clean() IFieldErrors {
|
|
return nil
|
|
}
|
|
|
|
func (m *Manager) CleanFields(name string) IFieldErrors {
|
|
return nil
|
|
}
|
|
|
|
func (m *Manager) GetTableName() string {
|
|
return getTableName(m.ins)
|
|
}
|