1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 23:01:28 +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,8 +21,12 @@ 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{
dbBasers = map[driverType]dbBaser{ "mysql": DR_MySQL,
"postgres": DR_Postgres,
"sqlite3": DR_Sqlite,
}
dbBasers = map[driverType]dbBaser{
DR_MySQL: newdbBaseMysql(), DR_MySQL: newdbBaseMysql(),
DR_Sqlite: newdbBaseSqlite(), DR_Sqlite: newdbBaseSqlite(),
DR_Oracle: newdbBaseMysql(), 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)
}

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

View File

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

View File

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

View File

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