1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-23 01:40:54 +00:00
Beego/orm/models_manager.go

92 lines
1.6 KiB
Go
Raw Normal View History

2013-07-30 12:32:38 +00:00
package orm
import ()
2013-07-31 14:11:22 +00:00
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}
}
2013-07-30 12:32:38 +00:00
// non cleaned field errors
2013-07-31 14:11:22 +00:00
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
}
2013-07-30 12:32:38 +00:00
2013-07-31 14:11:22 +00:00
func (fe *fieldErrors) List() []IFieldError {
return fe.errorList
2013-07-30 12:32:38 +00:00
}
2013-07-31 14:11:22 +00:00
func NewFieldErrors() IFieldErrors {
return &fieldErrors{errors: make(map[string]IFieldError)}
2013-07-30 12:32:38 +00:00
}
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()))
// }
// }
// }
// }
2013-08-01 01:23:32 +00:00
func (m *Manager) Init(model Modeler, args ...interface{}) Modeler {
2013-07-30 12:32:38 +00:00
if m.inited {
return m.ins
}
m.inited = true
m.ins = model
2013-08-01 01:23:32 +00:00
skipInitial := false
if len(args) > 0 {
if b, ok := args[0].(bool); ok && b {
skipInitial = true
}
}
_ = skipInitial
2013-07-30 12:32:38 +00:00
return model
}
func (m *Manager) IsInited() bool {
return m.inited
}
2013-07-31 14:11:22 +00:00
func (m *Manager) Clean() IFieldErrors {
2013-07-30 12:32:38 +00:00
return nil
}
2013-07-31 14:11:22 +00:00
func (m *Manager) CleanFields(name string) IFieldErrors {
2013-07-30 12:32:38 +00:00
return nil
}
func (m *Manager) GetTableName() string {
return getTableName(m.ins)
}