Skip to content

Instantly share code, notes, and snippets.

@mdedetrich
Created November 17, 2016 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdedetrich/850656f405b0c23645833b85194b7df3 to your computer and use it in GitHub Desktop.
Save mdedetrich/850656f405b0c23645833b85194b7df3 to your computer and use it in GitHub Desktop.
Array Extensions for Quill 1.0.0
trait ArrayExtensions extends io.getquill.context.jdbc.JdbcEncoders with io.getquill.context.jdbc.JdbcDecoders {
this: JdbcContext[PostgresDialect, _] =>
implicit def arrayStringDecoder[T]: Decoder[Array[String]] =
new Decoder[Array[String]] {
def apply(index: Int, row: ResultRow) = {
row.getArray(index + 1).getArray.asInstanceOf[Array[String]]
}
}
implicit def arrayStringEncoder(implicit e: Encoder[String]): Encoder[Array[String]] =
encoder[Array[String]](row => (idx, array) =>
{
val a = withConnection(conn => conn.createArrayOf("TEXT", array.asInstanceOf[Array[AnyRef]]))
row.setArray(idx, a)
},
java.sql.Types.ARRAY)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment