sqlx
sqlx copied to clipboard
How SQLX prints out the final executed SQL statement for debugging
Similar to db.lastsql ,THK
SQLX 如何打印输出最终执行的SQL语句用于调试,类似 db.lastsql,谢谢
@feikeq sqlx does not provide an out-of-the-box feature to log queries. However, you can create your own logger by using the sqlx.Named function, which helps bind parameters to the SQL statement before it's executed.
Here's how to do it:
query, args, err := sqlx.Named("SELECT * FROM table WHERE id=:id", map[string]interface{}{
"id": 1,
})
query, args, err = sqlx.In(query, args...)
query = db.Rebind(query)
fmt.Println(query)
You can wrap this pattern into a function and use it for debugging purposes.
INSERT INTO sys_user (remark,uptime,cell,nickname,company,fname,bankcard,grouptag,headimg,regip,referer,uid,intime,userclan,ciphers,birthday,address,city,province,country,username,email,sex,inviter,identity_card,object) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
打印出来的SQL语句不是完整的语句而是带有“?”问号的语句,依旧无法直接执行。@gurza
没有发自我的 iPhone在 2024年3月28日,21:30,Abner @.***> 写道: 您好,请问您解决该问题了吗?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: @.***>