1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-22 14:40:57 +00:00

some change

This commit is contained in:
slene 2013-08-01 09:23:32 +08:00
parent 831eeca7c8
commit b0b64eb404
5 changed files with 20 additions and 12 deletions

View File

@ -21,7 +21,11 @@ const (
var (
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{
DR_MySQL: newdbBaseMysql(),
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)
}

View File

@ -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
}

View File

@ -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)

View File

@ -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() {

View File

@ -14,7 +14,7 @@ type Fielder interface {
}
type Modeler interface {
Init(Modeler) Modeler
Init(Modeler, ...interface{}) Modeler
IsInited() bool
Clean() IFieldErrors
CleanFields(string) IFieldErrors