SQL调试
Debug
留意前面的文档中都有提到这个字段,它是用来控制某个ORM动作的时候是否将最终执行的SQL语句打印到控制台,默认不开启。可以通过全局config/config.yaml
上去配置,也可以单独在某个动作上配置。
tg.Source{
Link: "xx:xx@tcp(127.0.0.1:3306)/xx?charset=utf8mb4&parseTime=true&loc=Local",
Debug: true,
CreateTime: "create_time",
UpdateTime: "update_time",
DeleteTime: "delete_time",
MaxOpen: 100,
MaxIdle: 50,
MaxIdleTime: 0,
MaxLifeTime: 0,
}
tg.Source{
Link: "xx:xx@tcp(127.0.0.1:3306)/xx?charset=utf8mb4&parseTime=true&loc=Local",
Debug: true,
CreateTime: "create_time",
UpdateTime: "update_time",
DeleteTime: "delete_time",
MaxOpen: 100,
MaxIdle: 50,
MaxIdleTime: 0,
MaxLifeTime: 0,
}
局部控制 Debug
var user []User
err := tg.Db("user").Select(&user, tg.SelectOption{ Debug: tgutl.PtrBool(true) })
var user []User
err := tg.Db("user").Select(&user, tg.SelectOption{ Debug: tgutl.PtrBool(true) })
SQL: SELECT * FROM user
SQL: SELECT * FROM user