QueryFragment

class QueryFragment(val sql: String, val params: Map<String, Any?> = emptyMap())

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)

filter.sql goes to the clause and filter.params to the terminal, since a builder never carries parameters.

Constructors

Link copied to clipboard
constructor(sql: String, params: Map<String, Any?> = emptyMap())

Properties

Link copied to clipboard

Whether this fragment contributes nothing, so a clause leaves itself out.

Link copied to clipboard

The parameters the text names, without the leading @.

Link copied to clipboard
val sql: String

The SQL text. Empty where the fragment contributes nothing.

Functions

Link copied to clipboard
open override fun toString(): String