0

I'm using string interpolation with slick for generating sql request.

Slick string interpolation is working fine when I have less than 22 parameters.

Example:

val s = sql"select * from my_table where my_table.id = $i"

But as slick is using tuples and auto-tupling, I cannot write queries with more than 23 parameters.

Example:

val s = sql"""select * from my_table 
              where a1 = $i1 and a2 = $i2 and .... and a23 = $i23"""

For the moment the only solution I've found it's to create a new custom string interpolation for each query with more than 23 parameters.

Example:

  case class A(q1: Q1, q2: q2, ..., qn: Qn)

  implicit class CustomSQLInterpolation(val s: StringContext) extends AnyVal {
    /** Build a SQLInterpolationResult via string interpolation */
    def csql[P](q1: Q1, q2: Q2, ..., qn: Qn) = {
      val a = A(q1, q2, ..., qn)
      val setTupleA = new SetTupleParameter[A](
        SetQ1, SetQ2, ..., SetQ3)

      new SQLInterpolationResult[A](s.parts, a, setTupleA)
    }
  }

But this approach is not generic and not really convenient to use.

ulric260
  • 364
  • 4
  • 15

0 Answers0