-
-
Notifications
You must be signed in to change notification settings - Fork 304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
怎么在查询时field支持自定义sql #900
Comments
@RiverChu 看下文档的 dynamic sql |
gen.Field,能增加一个支持自定义sql的类型吗,现在的field转成sql都是 |
func NewRaw(ex clause.Expr) Field { 可不可以给field增加一个这样的方法,支持自定义sql |
我也遇到了同样的问题,比如我表里有两个字段x,y,我需要查询x<y+1的,这时候也需要动态的。 |
同问! |
This PR can help you to build customer raw field |
如果想在select或者where的时候自定义可以参考一下我 的一个做法,使用ast修改gen生成的代码,使生成的代码增加可以自定义select或者where的方法具体可以参考,对您有帮助的话帮我点一个star就是对我的鼓励 |
还有gen支持select 'value' custom_field, field1, field2这种格式吗,自定义一个表不存在的字段custom_field |
比如我有一张user表,表中有两个字段:id, status (pending, success ,failed),现在我需要一个sql查询出各个状态的数量
原生sql:
select
sum(if (u.status = 'pending' , 1, 0)) pending_count,
sum(if (u.status = 'success' , 1, 0)) pending_count,
sum(if (u.status = 'failed' , 1, 0)) pending_count
from user u
怎么使用gen实现呢
The text was updated successfully, but these errors were encountered: