QueryBuilder

little.sql.QueryBuilder
See theQueryBuilder companion object
trait QueryBuilder

Provides interface to incrementally build and execute SQL statements.

import java.sql.Connection

import scala.language.implicitConversions

import little.sql.{ *, given }

given Connection = ???

// Set parameters and execute query
QueryBuilder("select * from users where group = ? and enabled = ?")
 .params("staff", true)
 .maxRows(10)
 .foreach { rs => printf(s"uid=%d%n", rs.getInt("id")) }

// Same as above except use mapped 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")) }

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def execute[T](handler: Execution => T)(using conn: Connection): T

Executes statement and passes result to supplied handler.

Executes statement and passes result to supplied handler.

Value parameters

conn

connection to execute statement

handler

execution handler

Attributes

def fetchSize: Int

Gets fetch size.

Gets fetch size.

Attributes

def fetchSize(value: Int): QueryBuilder

Sets fetch size.

Sets fetch size.

Attributes

def maxRows: Int

Gets max rows.

Gets max rows.

Attributes

def maxRows(value: Int): QueryBuilder

Sets max rows.

Sets max rows.

Attributes

def params: Seq[InParam]

Gets parameters.

Gets parameters.

Attributes

def params(values: Seq[InParam]): QueryBuilder

Sets parameters.

Sets parameters.

Attributes

def params(values: Map[String, InParam]): QueryBuilder

Sets parameters using mapped values.

Sets parameters using mapped values.

Attributes

def query[T](f: ResultSet => T)(using conn: Connection): T

Executes query and passes result set to supplied function.

Executes query and passes result set to supplied function.

Value parameters

conn

connection to execute query

f

function

Attributes

def queryTimeout: Int

Gets query timeout.

Gets query timeout.

Attributes

def queryTimeout(value: Int): QueryBuilder

Sets query timeout.

Sets query timeout.

Attributes

def sql: String

Gets SQL.

Gets SQL.

Attributes

def update[T](f: Long => T)(using conn: Connection): T

Executes update and passes update count to supplied function.

Executes update and passes update count to supplied function.

Value parameters

conn

connection to execute update

f

function

Attributes

Concrete methods

def executeUpdate()(using conn: Connection): Long

Executes update and returns update count.

Executes update and returns update count.

Value parameters

conn

connection to execute update

Attributes

def first[T](f: ResultSet => T)(using conn: Connection): Option[T]

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 parameters

conn

connection to execute query

f

function

Attributes

def flatMap[T](f: ResultSet => Iterable[T])(using conn: Connection): Seq[T]

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 parameters

conn

connection to execute query

f

map function

Attributes

def fold[T](init: T)(op: (T, ResultSet) => T)(using conn: Connection): T

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 parameters

conn

connection to execute query

init

initial value

op

binary operator

Attributes

def foreach(f: ResultSet => Unit)(using conn: Connection): Unit

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 parameters

conn

connection to execute query

f

function

Attributes

def map[T](f: ResultSet => T)(using conn: Connection): Seq[T]

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 parameters

conn

connection to execute query

f

map function

Attributes

def params(one: InParam, more: InParam*): QueryBuilder

Sets parameters.

Sets parameters.

Attributes

def params(one: (String, InParam), more: (String, InParam)*): QueryBuilder

Sets parameters using mapped values.

Sets parameters using mapped values.

Attributes