Provides interface to incrementally build and execute SQL statements.
QueryBuilder
is an immutable structure. A new builder is returned with each
requested modification, and a new statement and result set are created on
each requested execution.
import java.sql.Connection
import scala.language.implicitConversions
import little.sql.Implicits.*
import little.sql.QueryBuilder
implicit val conn: Connection = ???
QueryBuilder("select * from users where group = ? and enabled = ?")
.params("staff", true) // Set input parameter values
.maxRows(10) // Limit result set to 10 rows
.foreach { rs => printf(s"uid=%d%n", rs.getInt("id")) } // Use implicit connection
// Same as above except use map of parameters
QueryBuilder("select * from users where group = ${group} and enabled = ${enabled}")
.params("group" -> "staff", "enabled" -> true)
.maxRows(10)
.foreach { rs => printf(s"uid=%d%n", rs.getInt("id")) }
- Companion
- object
Value members
Abstract methods
Executes statement and passes result to supplied handler.
Executes statement and passes result to supplied handler.
- Value Params
- conn
connection to execute statement
- handler
execution handler
Executes query and maps first row of result set using supplied function.
Executes query and maps first row of result set using supplied function.
If the result set is not empty, and if the supplied function's return
value is not null, then Some
value is returned; otherwise, None
is
returned.
- Value Params
- conn
connection to execute query
- f
function
Executes query and builds collection using elements mapped from each row of result set.
Executes query and builds collection using elements mapped from each row of result set.
- Value Params
- conn
connection to execute query
- f
map function
Executes query and folds result set to single value using given initial value and binary operator.
Executes query and folds result set to single value using given initial value and binary operator.
- Value Params
- conn
connection to execute query
- init
initial value
- op
binary operator
Executes query and invokes supplied function for each row of result set.
Executes query and invokes supplied function for each row of result set.
- Value Params
- conn
connection to execute query
- f
function
Executes update and returns update count.
Executes update and returns update count.
- Value Params
- conn
connection to execute update
Executes query and maps each row of result set using supplied function.
Executes query and maps each row of result set using supplied function.
- Value Params
- conn
connection to execute query
- f
map function