SQLboiler not in clause

Viewed 2050

I am trying to follow the examples in sqlboiler (https://github.com/volatiletech/sqlboiler). But, I can't find a way to get equivalent of NOT IN query.

users, err := models.Users(
  Select("id", "name"),
  Where("age > ?", 30),
  AndIn("c.kind in ?", "visa", "mastercard"),
).All(ctx, db)

In this example, if, we could get an operation AndNotIn, it'd be great.

Thanks!

3 Answers

I'm seeing AndNotIn in current versions of SQLBoiler generated code.

Looks like it was added on July 3rd, 2020.

use qm.WhereIn("c.kind not in ?", "visa", "mastercard")

or in a more universal format qm.WhereIn("someColumeName not in ?", values...)

notice that values should be already converted to []interface{}

Please use this

users, err := models.Users(qm.Select("id","name"),qm.Where("age > ?",30),model.UsersWhere.Kind.NIN([]string{"visa","mastercard"})).All(context.Background(),db)
if err != nil {
    fmt.Println("error is -- ",err)
}
resp, _ := json.Marshal(users)
fmt.Println("result ",bytes.NewBuffer(resp))

where imported package qm is -

"github.com/volatiletech/sqlboiler/v4/queries/qm"

Related