mirror of
https://github.com/astaxie/beego.git
synced 2024-12-23 03:50:51 +00:00
some change
This commit is contained in:
parent
831eeca7c8
commit
b0b64eb404
@ -21,8 +21,12 @@ const (
|
||||
|
||||
var (
|
||||
dataBaseCache = &_dbCache{cache: make(map[string]*alias)}
|
||||
drivers = make(map[string]driverType)
|
||||
dbBasers = map[driverType]dbBaser{
|
||||
drivers = map[string]driverType{
|
||||
"mysql": DR_MySQL,
|
||||
"postgres": DR_Postgres,
|
||||
"sqlite3": DR_Sqlite,
|
||||
}
|
||||
dbBasers = map[driverType]dbBaser{
|
||||
DR_MySQL: newdbBaseMysql(),
|
||||
DR_Sqlite: newdbBaseSqlite(),
|
||||
DR_Oracle: newdbBaseMysql(),
|
||||
@ -122,9 +126,3 @@ func RegisterDriver(name string, typ driverType) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterDriver("mysql", DR_MySQL)
|
||||
RegisterDriver("postgres", DR_Postgres)
|
||||
RegisterDriver("sqlite3", DR_Sqlite)
|
||||
}
|
||||
|
@ -58,12 +58,19 @@ type Manager struct {
|
||||
// }
|
||||
// }
|
||||
|
||||
func (m *Manager) Init(model Modeler) Modeler {
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ type orm struct {
|
||||
}
|
||||
|
||||
func (o *orm) Object(md Modeler) ObjectSeter {
|
||||
md.Init(md, true)
|
||||
name := md.GetTableName()
|
||||
if mi, ok := modelCache.get(name); ok {
|
||||
return newObject(o, mi, md)
|
||||
@ -38,8 +39,9 @@ func (o *orm) QueryTable(ptrStructOrTableName interface{}) QuerySeter {
|
||||
name := ""
|
||||
if table, ok := ptrStructOrTableName.(string); ok {
|
||||
name = snakeString(table)
|
||||
} else if m, ok := ptrStructOrTableName.(Modeler); ok {
|
||||
name = m.GetTableName()
|
||||
} else if md, ok := ptrStructOrTableName.(Modeler); ok {
|
||||
md.Init(md, true)
|
||||
name = md.GetTableName()
|
||||
}
|
||||
if mi, ok := modelCache.get(name); ok {
|
||||
return newQuerySet(o, mi)
|
||||
|
@ -17,6 +17,7 @@ func (o *insertSet) Insert(md Modeler) (int64, error) {
|
||||
if o.closed {
|
||||
return 0, ErrStmtClosed
|
||||
}
|
||||
md.Init(md, true)
|
||||
val := reflect.ValueOf(md)
|
||||
ind := reflect.Indirect(val)
|
||||
if val.Type() != o.mi.addrField.Type() {
|
||||
|
@ -14,7 +14,7 @@ type Fielder interface {
|
||||
}
|
||||
|
||||
type Modeler interface {
|
||||
Init(Modeler) Modeler
|
||||
Init(Modeler, ...interface{}) Modeler
|
||||
IsInited() bool
|
||||
Clean() IFieldErrors
|
||||
CleanFields(string) IFieldErrors
|
||||
|
Loading…
Reference in New Issue
Block a user