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 { implicit session =>
SQL("select * from user").map { rs =>
User(rs.int("id"), rs.string("name"))
}.list.apply()
}
DB(conn) autoCommit { implicit session =>
SQL("insert into user values (?,?)").bind(123, "Alice").update.apply()
}
DB(conn) localTx { implicit session =>
SQL("insert into user values (?,?)").bind(123, "Alice").update.apply()
}
}
Attributes
- Companion
- object
- Source
- DB.scala
- Graph
-
- Supertypes
-
trait Serializabletrait Producttrait Equalstrait DBConnectiontrait AutoCloseabletrait LoanPatternclass Objecttrait Matchableclass AnyShow all
Members list
Type members
Inherited types
Attributes
- Inherited from:
- LoanPattern
- Source
- LoanPattern.scala
Value members
Inherited methods
Switches auto close mode.
Switches auto close mode.
Value parameters
- autoClose
-
auto close enabled if true
Attributes
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Provides auto-commit session block.
Provides auto-commit session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns auto-commit session.
Returns auto-commit session.
Attributes
- Returns
-
session
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Provides auto-commit session block.
Provides auto-commit session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Begins a new transaction.
Begins a new transaction if the other one does not already start.
Begins a new transaction if the other one does not already start.
Attributes
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Close the connection.
Commits the current transaction.
Returns the current transaction. If the transaction has not started yet, IllegalStateException will be thrown.
Returns the current transaction. If the transaction has not started yet, IllegalStateException will be thrown.
Attributes
- Returns
-
tx
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns describe style string value for the table
Returns describe style string value for the table
Value parameters
- table
-
table name (with schema optionally)
Attributes
- Returns
-
described information
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Easy way to checkout the current connection to be used in a transaction that needs to be committed/rolled back depending on Future results.
Easy way to checkout the current connection to be used in a transaction that needs to be committed/rolled back depending on Future results.
Type parameters
- A
-
future result type
Value parameters
- execution
-
block that takes a session and returns a future
Attributes
- Returns
-
future result
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
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.
Attributes
- Inherited from:
- LoanPattern
- Source
- LoanPattern.scala
Returns columns resultset in schema.tableNames
Returns columns resultset in schema.tableNames
Value parameters
- meta
-
database meta data
- schema
-
schema name
- table
-
table name
Attributes
- Returns
-
resultset related to columns
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns all the column names on the matched table name
Returns all the column names on the matched table name
Attributes
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns table information if exists
Returns table information if exists
Value parameters
- table
-
table name (with schema optionally)
Attributes
- Returns
-
table information
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns all the table information that match the pattern
Returns all the table information that match the pattern
Value parameters
- tableNamePattern
-
table name pattern (with schema optionally)
Attributes
- Returns
-
table information
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns is the current transaction already started.
Returns is the current transaction already started.
Attributes
- Returns
-
result
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns is the current transaction is active.
Returns is the current transaction is active.
Attributes
- Returns
-
result
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns is the current transaction hasn't started yet.
Returns is the current transaction hasn't started yet.
Attributes
- Returns
-
result
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Set isolation level.
Provides local-tx session block.
Provides local-tx session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Provides local-tx session block.
Provides local-tx session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Starts a new transaction and returns it.
Starts a new transaction and returns it.
Attributes
- Returns
-
tx
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Attributes
- Inherited from:
- Product
Attributes
- Inherited from:
- Product
Provides read-only session block.
Provides read-only session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns read-only session.
Returns read-only session.
Attributes
- Returns
-
session
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Provides read-only session block.
Provides read-only session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Rolls back the current transaction.
Rolls back the current transaction.
Attributes
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Rolls back the current transaction if the transaction is still active.
Rolls back the current transaction if the transaction is still active.
Attributes
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns table name list
Returns table name list
Value parameters
- tableNamePattern
-
table name pattern
- tableTypes
-
table types
Attributes
- Returns
-
table name list
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns the current transaction. If the transaction has not started yet, IllegalStateException will be thrown.
Returns the current transaction. If the transaction has not started yet, IllegalStateException will be thrown.
Attributes
- Returns
-
tx
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Attributes
- Inherited from:
- LoanPattern
- Source
- LoanPattern.scala
Provides within-tx session block.
Provides within-tx session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Returns within-tx session.
Returns within-tx session.
Attributes
- Returns
-
session
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Provides within-tx session block.
Provides within-tx session block.
Type parameters
- A
-
return type
Value parameters
- execution
-
block
Attributes
- Returns
-
result value
- Inherited from:
- DBConnection
- Source
- DBConnection.scala
Inherited fields
Logger