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()))
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
func (m *Manager) Init(model Modeler) Modeler {
|
|
|
|
if m.inited {
|
|
|
|
return m.ins
|
|
|
|
}
|
|
|
|
m.inited = true
|
|
|
|
m.ins = model
|
|
|
|
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)
|
|
|
|
}
|