Scala slick query where in list

后端 未结 4 1374
忘掉有多难
忘掉有多难 2021-02-03 22:57

I am attempting to learn to use Slick to query MySQL. I have the following type of query working to get a single Visit object:

Q.query[(Int,Int), Visit](\"\"\"
          


        
4条回答
  •  旧巷少年郎
    2021-02-03 23:05

    You can generate in clause automaticly like this:

      def find(id: List[Long])(implicit options: QueryOptions) = {
        val in = ("?," * id.size).dropRight(1)
        Q.query[List[Long], FullCard](s"""
            select 
                o.id, o.name 
            from 
                organization o
            where
                o.id in ($in)
            limit
                ?
            offset
                ?
                """).list(id ::: options.limits)
      }
    

    And use implicit SetParameter as pagoda_5b says

      def seqParam[A](implicit pconv: SetParameter[A]): SetParameter[Seq[A]] = SetParameter {
        case (seq, pp) =>
          for (a <- seq) {
            pconv.apply(a, pp)
          }
      }
    
      implicit def setLongList = seqParam[Long]
    

提交回复
热议问题