Ok, so to map CITEXT
, which is not a standard type JDBC knows about, we need a wrapper class and need to move the value back and forth via the generic PGobject
data type.
import org.postgresql.util.PGobject
case class CIText(s: String)
object CIText {
implicit val CITextMeta: Meta[CIText] =
Meta.other[PGobject]("citext").xmap[CIText](
o => CIText(o.getValue),
a => {
val o = new PGobject
o.setType("citext")
o.setValue(a.s)
o
}
)
}
It works both as a parameter and return type.
@ sql"select cit from test where cit = ${CIText("foo")}".query[CIText].quick.unsafeRunSync
CIText(foo)
CIText(FOO)
And statement checking works now.
@ sql"select cit from test where cit = ${CIText("foo")}".query[CIText].check.unsafeRunSync
select cit from test where cit = ?
✓ SQL Compiles and Typechecks
✓ P01 CIText → OTHER (citext)
✓ C01 cit OTHER (citext) NOT NULL → CIText
@