Like operation MYSQL using SQLBoiler and golang

1k Views Asked by At

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

There are 1 best solutions below

0
On BEST ANSWER

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+"%"))
    }