【问题标题】:For yield with Rep[Optional[...]] using Slick对于使用 Slick 的 Rep[Optional[...]] 的产量
【发布时间】:2019-03-07 22:17:37
【问题描述】:

我正在尝试使用以下伪代码检查我的列是否包含提供的 List 中的至少一个元素:

其中 b.testColumn = Rep[Optional[List]].

def checkTest(id: UUID, input: List[String]) = {

  for {
    a <- a.query if a.id === id
    b <- b.query if a.bId === b.id && b.testColumn.intersect(input)
  } yield b

  ApplicationDatabase.slick.run...
}

我收到以下代码类型不匹配的错误:

b <- b.query if a.bId === b.id && b.testColumn.intersect(input)

我的问题是 - 如何轻松打开 Rep[Optional[...]] 并与我的输入值进行比较

【问题讨论】:

    标签: java scala functional-programming slick


    【解决方案1】:

    你试过inSet吗?

    b &lt;- b.query if a.bId === b.id &amp;&amp; b.testColumn.inSet(input)

    【讨论】:

    • 是的先生,只是为了澄清 testColumn 类型是 column[Option[List[String]]]
    • 你可以和Option一起使用。
    【解决方案2】:

    经过调查,我发现访问Rep[Optional[...]] 的最简单方法是使用.map

    例如- b &lt;- b.query if a.bId === b.id &amp;&amp; b.map(_.testColumn).inSetBind(input)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 2018-02-20
      • 2016-06-14
      相关资源
      最近更新 更多