doutu4335 2019-06-09 22:13
浏览 88

SQLBoiler从`AndIn`中的另一个表中选择

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!

  • 写回答

1条回答

  • doushi5913 2019-06-11 23:15
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法