【发布时间】:2020-07-04 22:39:45
【问题描述】:
我正在尝试使用 Kotlin 的扩展函数以类型安全的方式通过 PostgreSQL 的全文搜索扩展 jOOQ。
我的问题是 DSL.function 不“知道”我的自定义类/类型 TsQuery 和 TsVector 并引发异常。 Function 类本身没有公共构造函数。
org.jooq.exception.SQLDialectNotSupportedException:方言 DEFAULT 不支持类型类 jooq.fulltext.TsVector
class TsQuery
class TsVector
fun Field<String>.toTsVector(searchConfig: String): Field<TsVector> {
return DSL.function(
"to_tsvector",
TsVector::class.java,
DSL.inline(searchConfig),
DSL.coalesce(this, "")
)!!
}
fun String.toTsQuery(searchConfig: String): Field<TsQuery> {
return DSL.function(
"to_tsquery",
TsQuery::class.java,
DSL.inline(searchConfig),
DSL.value(this)
)!!
}
fun Field<TsVector>.tsMatches(query: Field<TsQuery>): Condition {
return DSL.condition(
"{0} @@ {1}",
this,
query
)!!
}
fun Field<TsVector>.tsRank(query: Field<TsQuery>): Field<Double> {
return DSL.function(
"ts_rank",
Double::class.java,
this,
query
)!!
}
如果我将 TsQuery 和 TsVector 替换为 String 则它可以工作,但我会丢失输入。 我只想将它们用于查询构建,我不需要能够将这些类型解析/转换为 Kotlin。
【问题讨论】:
标签: postgresql generics kotlin jooq