QueryFragment
A piece of SQL and the parameters it names, kept together so that a WHERE assembled at runtime cannot name a parameter nobody supplied. join combines them.
val filter = listOfNotNull(
name?.let { "cognomen ILIKE @name" withParam ("name" to "%$it%") },
minRank?.let { "rank_order >= @minRank" withParam ("minRank" to it) },
province?.let { "home_province = @province" withParam ("province" to it) }
).join(" AND ")
val senators = db.select("*").from("senate")
.where(filter.sql)
.fetchObjects<Senator>(filter.params)Content copied to clipboard
filter.sql goes to the clause and filter.params to the terminal, since a builder never carries parameters.