Active session implementation of scalikejdbc.DBSession.
All output decisions are unsupported by default.
All output decisions are unsupported by default.
return type
extractor constraint
Connection Pool using external DataSource
Connection Pool using external DataSource
Note: Commons-DBCP doesn't support this API.
BoneCP Connection Pool
BoneCP Connection Pool
Commons DBCP Connection Pool
Commons DBCP Connection Pool
Commons DBCP Connection Pool
Commons DBCP Connection Pool
Connection Pool
Connection pool context
Connection Pool Factory
Settings for ConnectionPool
Basic Database Accessor
Basic Database Accessor
Using DBSession:
import scalikejdbc._ case class User(id: Int, name: String) using(ConnectionPool(name).borrow()) { conn => val users = DB(conn) readOnly { session => session.list("select * from user") { rs => User(rs.int("id"), rs.string("name")) } } DB(conn) autoCommit { session => session.update("insert into user values (?,?)", 123, "Alice") } DB(conn) localTx { session => session.update("insert into user values (?,?)", 123, "Alice") } }
Using SQL:
import scalikejdbc._ case class User(id: Int, name: String) using(ConnectionPool.borrow()) { conn => val users = DB(conn) readOnly { session => SQL("select * from user").map { rs => User(rs.int("id"), rs.string("name")) }.list.apply() } DB(conn) autoCommit { session => SQL("insert into user values (?,?)").bind(123, "Alice").update.apply() } DB(conn) localTx { session => SQL("insert into user values (?,?)").bind(123, "Alice").update.apply() } }
Basic Database Accessor which holds a JDBC connection.
Additional attributes for current JDBC connection.
DB Session
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") } }
Connection Pool using external DataSource
Settings for DataSourceConnectionPool
Entity identifier provider for equality (especially for scalikejdbc.RelationalSQL operation).
Entity identifier provider for equality (especially for scalikejdbc.RelationalSQL operation).
Notice: Inheritance is not supported.
class Person(val id: Long) extends EntityEquality { override val entityIdentity = id } class Member(override val id: Long) extends Person(id) val p1 = new Person(123) val p2 = new Person(123) val m1 = new Member(123) val m2 = new Member(123) p1 == p2 && p2 == p1 // true p1 == m1 || m1 == p1 // false m1 == m2 && m2 == m1 // true
Represents that this SQL already has an extractor
Exception which represents that an illegal relationship is found.
Exception which represents invalid key is specified.
JDBC Settings
JDBC URL which contains host, port and database name
Utility to escape like condition special characters.
Loan pattern implementation
org.joda.time.LocalTime converter.
Settings for logging SQL and timing
Multiple connection pool context
Settings for Name binding SQL validator
Represents that already existing session will be used or a new session which is retrieved from named connection pool will be started.
Named Basic DB Accessor
Named Basic DB Accessor
It's easier to use named ConnectionPool with this class.
ConnectionPool.add('named, "jdbc:...", "user", "password") val users = NamedDB('named) readOnly { session => session.list("select * from user") }
Represents that this SQL doesn't have an extractor yet
Endpoint of one-to-x APIs
ParameterBinder which enables customizing StatementExecutor#binParams.
ParameterBinder which enables customizing StatementExecutor#binParams.
val bytes = Array[Byte](1,2,3, ...) val in = ByteArrayInputStream(bytes) val bin = ParameterBinder( value = in, binder = (stmt, idx) => stmt.setBinaryStream(idx, in, bytes.length) ) sql"insert into table (bin) values (${bin})".update.apply()
Represents that already existing session will be used or a new read-only session which is retrieved from named connection pool will be started.
java.sql.ResultSet cursor
Exception which represents failure on ResultSet extraction.
scala.collection.Traversable object which wraps java.sql.ResultSet.
SQL abstraction.
SQL abstraction.
return type
SQL which execute java.sql.Statement#executeBatch().
SQL which execute java.sql.Statement#execute().
SQL formatter
Settings for SQL formatter
SQLInterpolation definition
SQL to Collection
SQL to Collection
return type
extractor settings
SQL to List
SQL to List
return type
extractor settings
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.immutable.List value.
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.immutable.List value.
return type
SQL to Option
SQL to Option
return type
extractor settings
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.Option value.
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.Option value.
return type
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.Traversable value.
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.Traversable value.
return type
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.Traversable value.
SQL which execute java.sql.Statement#executeQuery() and returns the result as scala.collection.Traversable value.
return type
SQL which execute java.sql.Statement#executeUpdate().
SQL which execute java.sql.Statement#executeUpdate() and get generated key value.
BigDecimal converter.
Implicit conversions for BigDecimal values.
java.sql.Statement Executor.
java.sql.Statement Executor.
preparedStatement
SQL template
parameters for single execution (= not batch execution)
is batch flag
String SQL Runner
String SQL Runner
Basic Usage:
import scalikejdbc.StringSQLRunner._ val result: List[Map[String, Any]] = "insert into users values (1, 'Alice')".run() val users: List[Map[String, Any]] = "select * from users".run()
SQL value
Exception which represents too many rows returned.
DB Transaction abstraction.
This type class enable users to customize the behavior of transaction boundary(commit/rollback).
Type binder for java.sql.ResultSet.
Unix Time Converter to several types.
Implicit conversions for date time values.
Represents an extractor is already specified or not
java.sql.ResultSet wrapper.
Represents that already existing session will be used or a new session will be started.
Connection Pool Factory
Connection Pool Factory
Connection Pool Factory
Connection Pool Factory
Connection Pool Factory
Connection Pool Factory
Connection Pool
Connection Pool
Using Commons DBCP internally.
ConnectionPoolFactoryRepository
Basic Database Accessor
Basic Database Accessor
You can start with DB and blocks if using scalikejdbc.ConnectionPool.singleton().
Using DBSession:
ConnectionPool.singleton("jdbc:...","user","password") case class User(id: Int, name: String) val users = DB readOnly { session => session.list("select * from user") { rs => User(rs.int("id"), rs.string("name")) } } DB autoCommit { session => session.update("insert into user values (?,?)", 123, "Alice") } DB localTx { session => session.update("insert into user values (?,?)", 123, "Alice") } using(DB(ConnectionPool.borrow())) { db => db.begin() try { DB withTx { session => session.update("update user set name = ? where id = ?", "Alice", 123) } db.commit() } catch { case e => db.rollbackIfActive() throw e } }
Using SQL:
ConnectionPool.singleton("jdbc:...","user","password") case class User(id: Int, name: String) val users = DB readOnly { session => SQL("select * from user").map { rs => User(rs.int("id"), rs.string("name")) }.list.apply() } DB autoCommit { session => SQL("insert into user values (?,?)").bind(123, "Alice").update.apply() } DB localTx { session => SQL("insert into user values (?,?)").bind(123, "Alice").update.apply() } using(DB(ConnectionPool.borrow())) { db => db.begin() try { DB withTx { session => SQL("update user set name = ? where id = ?").bind("Alice", 123).update.apply() } db.commit() } catch { case e => db.rollbackIfActive() throw e } }
Generalized type constraints for WithExtractor
GlobalSettings for this library
Companion object of JDBC URL
No Connection Pool Context
Represents that there is no active session.
ParameterBinder factory.
Represents that already existing session will be used or a new read-only session will be started.
SQL abstraction's companion object.
SQL abstraction's companion object.
ConnectionPool.singleton("jdbc:...","user","password") case class User(id: Int, name: String) val users = DB.readOnly { session => SQL("select * from user").map { rs => User(rs.int("id"), rs.string("name")) }.list.apply() } DB .autoCommit { session => SQL("insert into user values (?,?)").bind(123, "Alice").update.apply() } DB localTx { session => SQL("insert into user values (?,?)").bind(123, "Alice").update.apply() } using(DB(ConnectionPool.borrow())) { db => db.begin() try { DB withTx { session => SQL("update user set name = ? where id = ?").bind("Alice", 123).update.apply() } db.commit() } catch { case e => db.rollbackIfActive() throw e } }
SQL Template Parser.
SQL Template Parser.
This parser supports following templates.
Basic SQL Template:
select * from user where id = ? and user_name = ?
Anorm-like SQL Template:
select * from user where id = {id} and user_name = {userName}
Executable SQL Template:
select * from user where id = /*'id*/123 and user_name = /*'userName*/\'Alice'
ExecutableSQL
is the template which contains parameter names just as comments with dummy values without specific syntax.
The template is a valid SQL, so you can check it is correct before building into app.
This object was generated by sbt-buildinfo.
Companion object.
Thread-local DB.
TxBoundary type class instances.
Type binder for java.sql.ResultSet.
Active session implementation of scalikejdbc.DBSession.
This class provides readOnly/autoCommit/localTx/withinTx blocks and session objects.
connection
transaction
is read only