Created
April 5, 2022 15:14
-
-
Save LukasForst/d8a4f62996308c447a2bbb5cbf284eea to your computer and use it in GitHub Desktop.
CitextColumnType
This file contains hidden or 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
/** | |
* 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