首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >类似于使用SQLBoiler和golang的MYSQL操作

类似于使用SQLBoiler和golang的MYSQL操作
EN

Stack Overflow用户
提问于 2021-07-21 23:09:29
回答 1查看 138关注 0票数 0

我想在MYSQL中使用SQL boiler和golang执行类似的操作

我正在使用

代码语言:javascript
复制
github.com/volatiletech/sqlboiler/v4/queries/qm

代码语言:javascript
复制
clause = qm.Where(fmt.Sprintf("post.deleted_at is null"))
    queryMods := []qm.QueryMod{
        clause,
        qm.Offset(gpi.Offset),
        qm.Limit(gpi.Limit),
        orderByMod,
        qm.Load(dbmodels.PostRels.ImpartWealth), // the user who posted
    }
    if searchKey != "" {
    where := fmt.Sprintf(`user on user.impart_wealth_id=post.impart_wealth_id 
and user.screen_name like ? or user.email like ? `)
queryMods = append(queryMods, qm.InnerJoin(where, "%"+searchKey +"%", "%"+searchKey +"%"))
    }
    posts, err := dbmodels.Posts(queryMods...).All(ctx, m.db)



[]qm.QueryMod{qmhelper.WhereQueryMod{Clause:"post.deleted_at is null",
 Args:[]interface {}(nil)}, 
qm.offsetQueryMod{offset:0},
 qm.limitQueryMod{limit:1}, 
qm.orderByQueryMod{clause:"created_at desc, post_id desc"},
qm.loadQueryMod{relationship:"ImpartWealth", mods:[]qm.QueryMod(nil)}, 
qm.innerJoinQueryMod{clause:"user on user.impart_wealth_id=post.impart_wealth_id \n\t\tand user.screen_name like ? or user.email like ? ",
 args:[]interface {}{"%j%", "%j%"}}}  

在这里Like是不起作用的。

数据正在获取,但就像操作不起作用一样,这不是获取使用电子邮件或屏幕名称过滤的数据。

过滤不起作用

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-22 01:04:35

我知道答案了。

代码语言:javascript
复制
if gpi.SearchKey != "" {
        where := fmt.Sprintf(`user on user.impart_wealth_id=post.impart_wealth_id 
        and (user.screen_name like ? or user.email like ? ) `)
        queryMods = append(queryMods, qm.InnerJoin(where, "%"+gpi.SearchKey+"%", "%"+gpi.SearchKey+"%"))
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68472044

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档