Finish upgrade the gorm framework.

This commit is contained in:
lishuang
2022-03-15 02:17:26 +08:00
parent 69412300b6
commit 161096fbb2
19 changed files with 167 additions and 187 deletions

View File

@ -4,6 +4,7 @@ import (
"github.com/eyebluecn/tank/code/core"
"github.com/eyebluecn/tank/code/tool/util"
"github.com/json-iterator/go"
"gorm.io/gorm/schema"
"io/ioutil"
"os"
"time"
@ -178,6 +179,14 @@ func (this *TankConfig) MatterPath() string {
return this.matterPath
}
//matter path
func (this *TankConfig) NamingStrategy() schema.NamingStrategy {
return schema.NamingStrategy{
TablePrefix: core.TABLE_PREFIX,
SingularTable: true,
}
}
//Finish the installation. Write config to tank.json
func (this *TankConfig) FinishInstall(mysqlPort int, mysqlHost string, mysqlSchema string, mysqlUsername string, mysqlPassword string, mysqlCharset string) {

View File

@ -75,6 +75,7 @@ func (this *TankContext) ServeHTTP(writer http.ResponseWriter, request *http.Req
func (this *TankContext) OpenDb() {
//log strategy.
dbLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
@ -84,9 +85,11 @@ func (this *TankContext) OpenDb() {
Colorful: false, // colorful print
},
)
//table name strategy.
namingStrategy := core.CONFIG.NamingStrategy()
var err error = nil
this.db, err = gorm.Open(mysql.Open(core.CONFIG.MysqlUrl()), &gorm.Config{Logger: dbLogger})
this.db, err = gorm.Open(mysql.Open(core.CONFIG.MysqlUrl()), &gorm.Config{Logger: dbLogger, NamingStrategy: namingStrategy})
if err != nil {
core.LOGGER.Panic("failed to connect mysql database")