From 5407a74aa33e76b50c272434020e2309886e87a0 Mon Sep 17 00:00:00 2001 From: xing Date: Mon, 7 Nov 2022 16:37:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0sql=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/db.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/db/db.go b/db/db.go index 306444c..2ec2f6c 100644 --- a/db/db.go +++ b/db/db.go @@ -5,6 +5,9 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/jmoiron/sqlx" "github/fthvgb1/wp-go/config" + "log" + "os" + "strings" ) var Db *sqlx.DB @@ -18,10 +21,16 @@ func NewSqlxDb(sqlx *sqlx.DB) *SqlxDb { } func (r SqlxDb) Select(ctx context.Context, dest any, sql string, params ...any) error { + if os.Getenv("SHOW_SQL") == "true" { + log.Printf(strings.Replace(sql, "?", "'%v'", -1), params...) + } return r.sqlx.Select(dest, sql, params...) } func (r SqlxDb) Get(ctx context.Context, dest any, sql string, params ...any) error { + if os.Getenv("SHOW_SQL") == "true" { + log.Printf(strings.Replace(sql, "?", "'%v'", -1), params...) + } return r.sqlx.Get(dest, sql, params...) }