From ff9df8f99cabb98915566296e6cb5985d89f113c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E6=B6=9B?= Date: Sat, 13 Aug 2022 07:18:06 +0800 Subject: [PATCH] =?UTF-8?q?enhance(db):=E5=8A=A0=E5=85=A5=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E6=A8=A1=E5=BC=8F=E7=9A=84SQL=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- global/db.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/global/db.go b/global/db.go index 7280554..0d8c1a4 100644 --- a/global/db.go +++ b/global/db.go @@ -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 }