Created
November 17, 2016 16:35
-
-
Save mdedetrich/850656f405b0c23645833b85194b7df3 to your computer and use it in GitHub Desktop.
Array Extensions for Quill 1.0.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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