-
Notifications
You must be signed in to change notification settings - Fork 545
Closed
Labels
Description
Description
🧜 With Json types now merged and bindObjectOther
in #5028 and #5040 Json operators
Support for a TSVector
column type can be added for bindObjectOther
and is returned as a String in the result set
e.g
CREATE TABLE t1 (
c1 TSVECTOR
);
INSERT INTO t1 (c1) VALUES ('the rain in spain falls mainly on the plains') ;
SELECT to_tsvector('the rain in spain falls mainly on the plain') @@ 'fail'
FROM t1;
Implementation
Add TSVECTOR
- Postgresql.bnf
tsvector_data_type ::= 'TSVECTOR'
- Match operator
'@@'
- used byJSON
andTSVECTOR
, how to handle that?
- Match operator
app.cash.sqldelight.dialects.postgresql.PostgreSqlType
app.cash.sqldelight.dialects.postgresql.PostgreSqlTypeResolver
internal enum class PostgreSqlType(override val javaType: TypeName) : DialectType {
...
TSVECTOR(STRING),
;
override fun prepareStatementBinder(columnIndex: CodeBlock, value: CodeBlock): CodeBlock {
return CodeBlock.builder()
.add(
when (this) {
...
TSVECTOR -> "bindObjectOther"
},
)
.add("(%L, %L)\n", columnIndex, value)
.build()
}
class PostgreSqlTypeResolver(private val parentResolver: TypeResolver) : TypeResolver by parentResolver {
override fun definitionType(typeName: SqlTypeName): IntermediateType = with(typeName) {
check(this is PostgreSqlTypeName)
val type = IntermediateType(
when {
...
tsvectorDataType != null -> PostgreSqlType.TSVECTOR
else -> throw IllegalArgumentException("Unknown kotlin type for sql type ${this.text}")
},
Add some functions
private fun SqlFunctionExpr.postgreSqlFunctionType() = when (functionName.text.lowercase()) {
...
"to_tsquery" -> IntermediateType(TEXT)
"to_tsvector" -> IntermediateType(PostgreSqlType.TSVECTOR)
else -> null