0

I am trying to follow the examples in sqlboiler (https://github.com/volatiletech/sqlboiler). But, I can't find a way to add another table in AndIn clause, since any Where leads to return two values.

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 a filter a way to fetch values from another table, it'd be equivalent to SQL.

One way to get this done is to obtain the values separately and then feed it in as a variable.

Thanks!

Matt Mc
  • 8,882
  • 6
  • 53
  • 89
Coder
  • 1,415
  • 2
  • 23
  • 49

1 Answers1

0

You can use arbitrary SQL in Where.

users, err := models.Users(
  Select("id", "name"),
  Where("age > ?", 30),
  Where("c.kind IN (select kind from your_other_table)"),
).All(ctx, db)

WhereIn, AndIn are just handy functions to autogenerate a list of a variable amount of placeholders. WhereIn("x in ?", "a", "b") is the same as Where("x in (?, ?)", "a", "b"). If you don't need that, just use regular Where.

Dirbaio
  • 2,921
  • 16
  • 15