标签:operator mysql cte 配置 property utf8mb4 doc create exists
ent 生成的代码client 包中包含了一个方便的方法Debug()
, 记得昨天我为了查看生成的sql 查询通过配置mysql
启用慢查询,同时设置记录慢查询为0,实际上client Debug 方法使用了builder 的模式,我们通过Debug 方法
可以直接就方便的输出生成的sql
if err := client.Debug().Schema.Create(ctx); err != nil {
log.Fatalf("failed printing schema changes: %v", err)
}
go run cmd/migration/main.go
2019/10/15 11:03:07 driver.Tx(661af82b-dd17-4c45-b721-88118838ca8e): started
2019/10/15 11:03:07 Tx(661af82b-dd17-4c45-b721-88118838ca8e).Query: query=SHOW VARIABLES LIKE ‘version‘ args=[]
2019/10/15 11:03:07 Tx(661af82b-dd17-4c45-b721-88118838ca8e).Query: query=SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SEL
ECT DATABASE()) AND `TABLE_NAME` = ? args=[groups]
2019/10/15 11:03:07 Tx(661af82b-dd17-4c45-b721-88118838ca8e).Exec: query=CREATE TABLE IF NOT EXISTS `groups`(`id` bigint AUTO_INCREMENT NOT NULL, `n
ame` varchar(255) NOT NULL, `admin_id` bigint NULL, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin args=[]
2019/10/15 11:03:07 Tx(661af82b-dd17-4c45-b721-88118838ca8e).Query: query=SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SEL
ECT DATABASE()) AND `TABLE_NAME` = ? args=[pets]
2019/10/15 11:03:07 Tx(661af82b-dd17-4c45-b721-88118838ca8e).Exec: query=CREATE TABLE IF NOT EXISTS `pets`(`id` bigint AUTO_INCREMENT NOT NULL, `nam
e` varchar(255) NOT NULL, `owner_id` bigint NULL, PRIMARY KEY(`id`)) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin args=[]
2019/10/15 11:03:07 Tx(661af82b-dd17-4c45-b721-88118838ca8e).Query: query=SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE `TABLE_SCHEMA` = (SEL
https://entgo.io/docs/getting-started/
标签:operator mysql cte 配置 property utf8mb4 doc create exists
原文地址:https://www.cnblogs.com/rongfengliang/p/11676540.html