DBSession

trait DBSession extends LogSupport with LoanPattern with AutoCloseable

DB Session

This class provides readOnly/autoCommit/localTx/withinTx blocks and session objects.

import scalikejdbc._

val userIdList = DB autoCommit { session: DBSession =>
 session.list("select * from user") { rs => rs.int("id") }
}
Companion
object
trait AutoCloseable
trait LogSupport
class Object
trait Matchable
class Any

Type members

Inherited types

type Closable = { def close(): Unit; }
Inherited from
LoanPattern

Value members

Concrete methods

def batch[C[_]](template: String, paramsList: Seq[Any]*)(implicit f: Factory[Int, C[Int]]): C[Int]

Executes java.sql.PreparedStatement#executeBatch().

Executes java.sql.PreparedStatement#executeBatch().

Value Params
paramsList

list of parameters

template

SQL template

Returns

count list

def batchAndReturnGeneratedKey[C[_]](template: String, paramsList: Seq[Any]*)(implicit f: Factory[Long, C[Long]]): C[Long]

Executes java.sql.PreparedStatement#executeBatch() and returns numeric generated keys.

Executes java.sql.PreparedStatement#executeBatch() and returns numeric generated keys.

Value Params
paramsList

list of parameters

template

SQL template

Returns

generated keys

def batchAndReturnSpecifiedGeneratedKey[C[_]](template: String, key: String, paramsList: Seq[Any]*)(implicit f: Factory[Long, C[Long]]): C[Long]

Executes java.sql.PreparedStatement#executeBatch() and returns numeric generated keys.

Executes java.sql.PreparedStatement#executeBatch() and returns numeric generated keys.

Value Params
key

generated key name

paramsList

list of parameters

template

SQL template

Returns

generated keys

def close(): Unit

Close the connection.

Close the connection.

def collection[A, C[_]](template: String, params: Any*)(extract: WrappedResultSet => A)(implicit f: Factory[A, C[A]]): C[A]

Returns query result as any Collection object.

Returns query result as any Collection object.

Type Params
A

return type

C

return collection type

Value Params
extract

extract function

params

parameters

template

SQL template

Returns

result as C[A]

def execute(template: String, params: Any*): Boolean

Executes java.sql.PreparedStatement#execute().

Executes java.sql.PreparedStatement#execute().

Value Params
params

parameters

template

SQL template

Returns

flag

def executeLargeUpdate(template: String, params: Any*): Long

Executes java.sql.PreparedStatement#executeLargeUpdate().

Executes java.sql.PreparedStatement#executeLargeUpdate().

Value Params
params

parameters

template

SQL template

Returns

result count

def executeUpdate(template: String, params: Any*): Int

Executes java.sql.PreparedStatement#executeUpdate().

Executes java.sql.PreparedStatement#executeUpdate().

Value Params
params

parameters

template

SQL template

Returns

result count

def executeWithFilters(before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Boolean

Executes java.sql.PreparedStatement#execute().

Executes java.sql.PreparedStatement#execute().

Value Params
after

after filter

before

before filter

params

parameters

template

SQL template

Returns

flag

def fetchSize(fetchSize: Int): DBSession

Set fetchSize for this session.

Set fetchSize for this session.

Value Params
fetchSize

fetch size

Returns

this

def fetchSize(fetchSize: Option[Int]): DBSession
def fetchSize: Option[Int]

Returns fetchSize for this session.

Returns fetchSize for this session.

Returns

fetch size

def first[A](template: String, params: Any*)(extract: WrappedResultSet => A): Option[A]

Returns the first row optionally.

Returns the first row optionally.

Type Params
A

return type

Value Params
extract

extract function

params

parameters

template

SQL template

Returns

result optionally

def foldLeft[A](template: String, params: Any*)(z: A)(op: (A, WrappedResultSet) => A): A

folding into one value.

folding into one value.

Value Params
op

function

params

parameters

template

SQL template

z

initial value

Returns

folded value

def foreach(template: String, params: Any*)(f: WrappedResultSet => Unit): Unit

Applies side-effect to each row iteratively.

Applies side-effect to each row iteratively.

Value Params
f

function

params

parameters

template

SQL template

Returns

result as list

def iterable[A](template: String, params: Any*)(extract: WrappedResultSet => A): Iterable[A]

Returns query result as scala.collection.Iterable object.

Returns query result as scala.collection.Iterable object.

Type Params
A

return type

Value Params
extract

extract function

params

parameters

template

SQL template

Returns

result as iterable

def largeBatch[C[_]](template: String, paramsList: Seq[Any]*)(implicit f: Factory[Long, C[Long]]): C[Long]

Executes java.sql.PreparedStatement#executeLargeBatch().

Executes java.sql.PreparedStatement#executeLargeBatch().

Value Params
paramsList

list of parameters

template

SQL template

Returns

count list

def largeUpdateWithAutoGeneratedKeyNameAndFilters(returnGeneratedKeys: Boolean, generatedKeyName: String, before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Long

Executes java.sql.PreparedStatement#executeLargeUpdate().

Executes java.sql.PreparedStatement#executeLargeUpdate().

Value Params
after

after filter

before

before filter

generatedKeyName

generated key name

params

parameters

returnGeneratedKeys

is generated keys required

template

SQL template

Returns

result count

def largeUpdateWithFilters(before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Long

Executes java.sql.PreparedStatement#executeLargeUpdate().

Executes java.sql.PreparedStatement#executeLargeUpdate().

Value Params
after

after filter

before

before filter

params

parameters

template

SQL template

Returns

result count

def largeUpdateWithFilters(returnGeneratedKeys: Boolean, before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Long

Executes java.sql.PreparedStatement#executeLargeUpdate().

Executes java.sql.PreparedStatement#executeLargeUpdate().

Value Params
after

after filter

before

before filter

params

parameters

returnGeneratedKeys

is generated keys required

template

SQL template

Returns

result count

def list[A](template: String, params: Any*)(extract: WrappedResultSet => A): List[A]

Returns query result as scala.List object.

Returns query result as scala.List object.

Type Params
A

return type

Value Params
extract

extract function

params

parameters

template

SQL template

Returns

result as list

def queryTimeout(seconds: Int): DBSession

Set queryTimeout to this session.

Set queryTimeout to this session.

Value Params
seconds

query timeout seconds

Returns

this

def queryTimeout(seconds: Option[Int]): DBSession
def queryTimeout: Option[Int]

Returns queryTimeout for this session.

Returns queryTimeout for this session.

Returns

query timeout seconds

def single[A](template: String, params: Any*)(extract: WrappedResultSet => A): Option[A]

Returns single result optionally. If the result is not single, scalikejdbc.TooManyRowsException will be thrown.

Returns single result optionally. If the result is not single, scalikejdbc.TooManyRowsException will be thrown.

Type Params
A

return type

Value Params
extract

extract function

params

parameters

template

SQL template

Returns

result optionally

def tags(tags: String*): DBSession

Set tags to this session.

Set tags to this session.

Value Params
tags

tags

Returns

this

def tags: Seq[String]

Returns tags for this session.

Returns tags for this session.

Returns

tags

def toStatementExecutor(template: String, params: Seq[Any], returnGeneratedKeys: Boolean): StatementExecutor
def tx: Option[Tx]

Returns current transaction if exists.

Returns current transaction if exists.

def update(template: String, params: Any*): Int

Executes java.sql.PreparedStatement#executeUpdate().

Executes java.sql.PreparedStatement#executeUpdate().

Value Params
params

parameters

template

SQL template

Returns

result count

def updateAndReturnGeneratedKey(template: String, params: Any*): Long

Executes java.sql.PreparedStatement#executeUpdate() and returns the generated key.

Executes java.sql.PreparedStatement#executeUpdate() and returns the generated key.

Value Params
params

parameters

template

SQL template

Returns

generated key as a long value

def updateAndReturnSpecifiedGeneratedKey(template: String, params: Any*)(key: Any): Long

Executes java.sql.PreparedStatement#executeUpdate() and returns the generated key.

Executes java.sql.PreparedStatement#executeUpdate() and returns the generated key.

Value Params
key

name

params

parameters

template

SQL template

Returns

generated key as a long value

def updateWithAutoGeneratedKeyNameAndFilters(returnGeneratedKeys: Boolean, generatedKeyName: String, before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Int

Executes java.sql.PreparedStatement#executeUpdate().

Executes java.sql.PreparedStatement#executeUpdate().

Value Params
after

after filter

before

before filter

generatedKeyName

generated key name

params

parameters

returnGeneratedKeys

is generated keys required

template

SQL template

Returns

result count

def updateWithFilters(before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Int

Executes java.sql.PreparedStatement#executeUpdate().

Executes java.sql.PreparedStatement#executeUpdate().

Value Params
after

after filter

before

before filter

params

parameters

template

SQL template

Returns

result count

def updateWithFilters(returnGeneratedKeys: Boolean, before: PreparedStatement => Unit, after: PreparedStatement => Unit, template: String, params: Any*): Int

Executes java.sql.PreparedStatement#executeUpdate().

Executes java.sql.PreparedStatement#executeUpdate().

Value Params
after

after filter

before

before filter

params

parameters

returnGeneratedKeys

is generated keys required

template

SQL template

Returns

result count

Inherited methods

def futureUsing[R <: Closable, A](resource: R)(f: R => Future[A])(implicit ec: ExecutionContext): Future[A]

Guarantees a Closeable resource will be closed after being passed to a block that takes the resource as a parameter and returns a Future.

Guarantees a Closeable resource will be closed after being passed to a block that takes the resource as a parameter and returns a Future.

Inherited from
LoanPattern
def using[R <: Closable, A](resource: R)(f: R => A): A
Inherited from
LoanPattern

Abstract fields

val isReadOnly: Boolean

is read-only session

is read-only session

Concrete fields

lazy val connection: Connection

Connection

Connection

Inherited fields

protected val log: Log

Logger

Logger

Inherited from
LogSupport