英文:
Like operation MYSQL using SQLBoiler and golang
问题
我想在使用SQL boiler和golang的MYSQL中执行LIKE操作。
我正在使用:
github.com/volatiletech/sqlboiler/v4/queries/qm
。
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操作不起作用。
数据可以获取,但是LIKE操作不起作用,无法获取使用电子邮件或屏幕名称进行筛选的数据。
筛选不起作用。
英文:
I want to Perform LIKE operation in MYSQL using SQL boiler and golang
I am using
github.com/volatiletech/sqlboiler/v4/queries/qm
.
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%"}}}
Here Like is not working.
Data is getting, but like operation not working, that is not getting the data that filter using the email or screenname.
filtering not working
答案1
得分: 0
我得到了答案。
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+"%"))
}
英文:
I got the Answer.
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+"%"))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论