enhance(db):加入调试模式的SQL输出。

This commit is contained in:
徐涛 2022-08-13 07:18:06 +08:00
parent b2812b3e6d
commit ff9df8f99c

View File

@ -2,6 +2,7 @@ package global
import (
"fmt"
"strings"
"time"
"electricity_bill_calc/config"
@ -9,6 +10,7 @@ import (
// _ "github.com/lib/pq"
_ "github.com/jackc/pgx/v5/stdlib"
"xorm.io/xorm"
"xorm.io/xorm/log"
)
var (
@ -44,5 +46,10 @@ func SetupDatabaseConnection() error {
DBConn.SetMaxOpenConns(config.DatabaseSettings.MaxOpenConns)
DBConn.SetConnMaxLifetime(60 * time.Second)
if strings.ToLower(config.ServerSettings.RunMode) == "debug" {
DBConn.ShowSQL(true)
DBConn.Logger().SetLevel(log.LOG_DEBUG)
}
return nil
}