Stelios Papamichail
09/21/2024, 11:15 PMStelios Papamichail
09/22/2024, 3:18 PMChantal Loncle
09/22/2024, 3:21 PMStringColumnType
to reduce some boilerplate:
class TsVectorColumnType : StringColumnType() {
override fun sqlType(): String = "tsvector"
override fun setParameter(stmt: PreparedStatementApi, index: Int, value: Any?) {
val parameterValue: PGobject? = value?.let {
PGobject().apply {
type = sqlType()
this.value = value as? String
}
}
super.setParameter(stmt, index, parameterValue)
}
}
registerColumn()
would need to be invoked in the table definition to actually map to the created column in the database:
fun Table.tsVector(name: String): Column<String> = registerColumn(name, TsVectorColumnType())
Please see docs for more examples of how to implement and use custom data types.
I'm having trouble understanding how the logic would work for using it to search based on the user's query.I'm not sure what you mean. Do you have an example of the exact SQL query that you need to generate? For a simple example, you could use the custom functions from the linked GH issue to create a query like this:
object StarWarsFilms : Table("star_wars_films") {
val title = varchar("title", 128)
val titleTS = tsVector("title_ts")
}
// inserts...
// I'm not sure if you are using a trigger to insert into the tsvector column.
// For simplicity I used an insert that just calls toTSVector() on the title string
StarWarsFilms
.select(StarWarsFilms.title)
.where { StarWarsFilms.titleTS tsMatches toTSQuery("Star") }
.toList()
// SELECT star_wars_films.title
// FROM star_wars_films
// WHERE star_wars_films.title_ts @@ to_tsquery('Star')