Skip to content

Instantly share code, notes, and snippets.

@mesut
mesut / jdbcarray.scala
Created February 13, 2020 11:31
scalikejdbc custom array types
implicit def sqlArrayToIntListBinder: Binders[List[Int]] = {
def sqlArrayToIntList(a: java.sql.Array): List[Int] = a.getArray.asInstanceOf[Array[AnyRef]].map(_.asInstanceOf[Int]).toList
Binders[List[Int]]((r, i) => sqlArrayToIntList(r.getArray(i)))((r, s) => sqlArrayToIntList(r.getArray(s)))(list => (s, i) => {
val array = s.getConnection.createArrayOf("integer", list.map(_.asInstanceOf[AnyRef]).toArray)
s.setArray(i, array)
})
}
implicit def sqlArrayToStringListBinder: Binders[List[String]] = {