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