Skip to content

Instantly share code, notes, and snippets.

@LukasForst
Created April 5, 2022 15:14
Show Gist options
  • Save LukasForst/d8a4f62996308c447a2bbb5cbf284eea to your computer and use it in GitHub Desktop.
Save LukasForst/d8a4f62996308c447a2bbb5cbf284eea to your computer and use it in GitHub Desktop.
CitextColumnType
/**
* Case Insensitive column type for Postgres.
*/
open class CitextColumnType : ColumnType() {
override fun sqlType(): String = "citext"
override fun readObject(rs: ResultSet, index: Int): Any? = rs.getBytes(index).decodeToString()
override fun valueFromDB(value: Any): Any = when (value) {
is Blob -> value.binaryStream.use { it.readBytes() }.decodeToString()
is InputStream -> value.use { it.readBytes() }.decodeToString()
else -> value
}
override fun nonNullValueToString(value: Any): String = when (value) {
is ByteArray -> value.decodeToString()
else -> value.toString()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment