scalikejdbc

DB

case class DB(conn: Connection) extends LogSupport with Product with Serializable

Basic Database Accessor

Using DBSession:

import scalikejdbc._
case class User(id: Int, name: String)

using(connectionPool(context).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()
  }

}
Linear Supertypes
Serializable, Serializable, Product, Equals, LogSupport, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. DB
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. LogSupport
  7. AnyRef
  8. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new DB(conn: Connection)

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def autoCommit[A](execution: (DBSession) ⇒ A): A

    Provides auto-commit session block.

    Provides auto-commit session block.

    A

    return type

    execution

    block

    returns

    result value

  8. def autoCommitSession(): DBSession

    Returns auto-commit session.

    Returns auto-commit session.

    returns

    session

  9. def autoCommitWithConnection[A](execution: (Connection) ⇒ A): A

    Provides auto-commit session block.

    Provides auto-commit session block.

    A

    return type

    execution

    block

    returns

    result value

  10. def begin(): Unit

    Begins a new transaction.

  11. def beginIfNotYet(): Unit

    Begins a new transaction if the other one does not already start.

  12. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  13. def close(): Unit

    Close the connection.

  14. def commit(): Unit

    Commits the current transaction.

  15. val conn: Connection

  16. def currentTx: Tx

    Returns the current transaction.

    Returns the current transaction. If the transaction has not started yet, IllegalStateException will be thrown.

    returns

    tx

  17. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  18. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  19. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  20. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  21. def isTxAlreadyStarted: Boolean

    Returns is the current transaction already started.

    Returns is the current transaction already started.

    returns

    result

  22. def isTxNotActive: Boolean

    Returns is the current transaction is active.

    Returns is the current transaction is active.

    returns

    result

  23. def isTxNotYetStarted: Boolean

    Returns is the current transaction hasn't started yet.

    Returns is the current transaction hasn't started yet.

    returns

    result

  24. def localTx[A](execution: (DBSession) ⇒ A): A

    Provides local-tx session block.

    Provides local-tx session block.

    A

    return type

    execution

    block

    returns

    result value

  25. def localTxWithConnection[A](execution: (Connection) ⇒ A): A

    Provides local-tx session block.

    Provides local-tx session block.

    A

    return type

    execution

    block

    returns

    result value

  26. val log: Log

    Logger

    Logger

    Attributes
    protected
    Definition Classes
    LogSupport
  27. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  28. def newTx: Tx

    Starts a new transaction and returns it.

    Starts a new transaction and returns it.

    returns

    tx

  29. final def notify(): Unit

    Definition Classes
    AnyRef
  30. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  31. def readOnly[A](execution: (DBSession) ⇒ A): A

    Provides read-only session block.

    Provides read-only session block.

    A

    return type

    execution

    block

    returns

    result value

  32. def readOnlySession(): DBSession

    Returns read-only session.

    Returns read-only session.

    returns

    session

  33. def readOnlyWithConnection[A](execution: (Connection) ⇒ A): A

    Provides read-only session block.

    Provides read-only session block.

    A

    return type

    execution

    block

    returns

    result value

  34. def rollback(): Unit

    Rolls back the current transaction.

  35. def rollbackIfActive(): Unit

    Rolls back the current transaction if the transaction is still active.

  36. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  37. def tx: Tx

    Returns the current transaction.

    Returns the current transaction. If the transaction has not started yet, IllegalStateException will be thrown.

    returns

    tx

  38. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  39. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  40. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  41. def withinTx[A](execution: (DBSession) ⇒ A): A

    Provides within-tx session block.

    Provides within-tx session block.

    A

    return type

    execution

    block

    returns

    result value

  42. def withinTxSession(tx: Tx = currentTx): DBSession

    Returns within-tx session.

    Returns within-tx session.

    returns

    session

  43. def withinTxWithConnection[A](execution: (Connection) ⇒ A): A

    Provides within-tx session block.

    Provides within-tx session block.

    A

    return type

    execution

    block

    returns

    result value

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from LogSupport

Inherited from AnyRef

Inherited from Any

No Group