chore: 改用函数暴露句柄
This commit is contained in:
parent
ac51a6a211
commit
72aa931caa
@ -21,7 +21,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var DM *DbMap
|
||||
var dm *DbMap
|
||||
|
||||
type DbOption struct {
|
||||
Type string
|
||||
@ -65,13 +65,24 @@ func InitDb(opt DbOption) error {
|
||||
default:
|
||||
return errors.New("unrecognized database driver")
|
||||
}
|
||||
DM = &DbMap{
|
||||
dm = &DbMap{
|
||||
Db: db,
|
||||
Dialect: dialect,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 通过函数暴露句柄
|
||||
func GetDm() *DbMap {
|
||||
if dm == nil {
|
||||
InitDb(DbOption{
|
||||
Type: "sqlite3",
|
||||
Dsn: ":memory:",
|
||||
})
|
||||
}
|
||||
return dm
|
||||
}
|
||||
|
||||
// DbMap is the root sqldb mapping object. Create one of these for each
|
||||
// database schema you wish to map. Each DbMap contains a list of
|
||||
// mapped tables.
|
||||
|
Loading…
Reference in New Issue
Block a user