|
@@ -4,16 +4,20 @@ import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
|
|
|
|
|
"mtp2_if/config"
|
|
"mtp2_if/config"
|
|
|
|
|
+ "mtp2_if/logger"
|
|
|
|
|
|
|
|
"github.com/xormplus/core"
|
|
"github.com/xormplus/core"
|
|
|
"github.com/xormplus/xorm"
|
|
"github.com/xormplus/xorm"
|
|
|
|
|
+ "github.com/xormplus/xorm/log"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
//var driverName = "oci8"
|
|
//var driverName = "oci8"
|
|
|
//var dataSourceName = "mtp2_test18/muchinfo@192.168.31.117:1521/orcl"
|
|
//var dataSourceName = "mtp2_test18/muchinfo@192.168.31.117:1521/orcl"
|
|
|
|
|
+
|
|
|
|
|
+// Engine DB Engine
|
|
|
var Engine *xorm.Engine
|
|
var Engine *xorm.Engine
|
|
|
|
|
|
|
|
-// NewDbDriver 创建数据库驱动
|
|
|
|
|
|
|
+// InitDbEngine 创建数据库驱动
|
|
|
func InitDbEngine() error {
|
|
func InitDbEngine() error {
|
|
|
driverName := config.SerCfg.GetDbDriver()
|
|
driverName := config.SerCfg.GetDbDriver()
|
|
|
dataSourceName := config.SerCfg.GetDbSource()
|
|
dataSourceName := config.SerCfg.GetDbSource()
|
|
@@ -27,16 +31,24 @@ func InitDbEngine() error {
|
|
|
|
|
|
|
|
Engine.SetMaxIdleConns(10)
|
|
Engine.SetMaxIdleConns(10)
|
|
|
Engine.SetMaxOpenConns(100)
|
|
Engine.SetMaxOpenConns(100)
|
|
|
|
|
+
|
|
|
|
|
+ // 将SQL写到日志文件
|
|
|
|
|
+ logger := log.NewSimpleLogger(logger.GetLogWriter())
|
|
|
|
|
+ Engine.SetLogger(logger)
|
|
|
|
|
+ // 将SQL打印到Console
|
|
|
Engine.ShowSQL(true)
|
|
Engine.ShowSQL(true)
|
|
|
|
|
+
|
|
|
Engine.SetTableMapper(core.SameMapper{})
|
|
Engine.SetTableMapper(core.SameMapper{})
|
|
|
|
|
|
|
|
return nil
|
|
return nil
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// GetEngine GetEngine
|
|
|
func GetEngine() *xorm.Engine {
|
|
func GetEngine() *xorm.Engine {
|
|
|
return Engine
|
|
return Engine
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// Close Close
|
|
|
func Close() {
|
|
func Close() {
|
|
|
Engine.Close()
|
|
Engine.Close()
|
|
|
}
|
|
}
|