little.sql
Type members
Classlikes
Provides extension methods for java.sql.Connection
.
Provides extension methods for java.sql.Connection
.
import scala.language.implicitConversions
import little.sql.{ *, given }
val connector = Connector("jdbc:h2:~/test", "sa", "s3cr3t", "org.h2.Driver")
connector.withConnection { conn =>
val statements = Seq(
"drop table prog_lang if exists",
"create table prog_lang (id int, name text)",
"insert into prog_lang (id, name) values (1, 'basic'), (2, 'pascal'), (3, 'c')",
"select * from prog_lang"
)
statements.foreach { sql =>
// Execute SQL and handle execution result accordingly
conn.execute(sql) {
// If update is executed print update count
case Update(count) ⇒ println(s"Update Count: $count")
// If query is executed print values of each row in ResultSet
case Query(resultSet) =>
while (resultSet.next())
printf("id: %d, name: %s%n", resultSet.getInt("id"), resultSet.getString("name"))
}
}
}
Provides basic implementation of data source.
Provides basic implementation of data source.
- Value parameters:
- driverClassName
fully qualified class name of JDBC driver
- driverClassPath
class path from which JDBC driver is loaded
- password
data source password
- url
data source url
- user
data source user
- Note:
If
driverClassPath
is empty, the driver is loaded using this instance's class loader; otherwise, the driver is loaded using a class loader constructed from supplied class path.
Provides extension methods for javax.sql.DataSource
.
Provides extension methods for javax.sql.DataSource
.
Represents result of either update or query. If update, result can be
obtained via count
; otherwise, if query, result can be obtained via
resultSet
.
Represents result of either update or query. If update, result can be
obtained via count
; otherwise, if query, result can be obtained via
resultSet
.
- See also:
- Companion:
- object
Provides factory methods for Execution.
Provides factory methods for Execution.
- Companion:
- class
Gets BigDecimal from ResultSet.
Gets BigDecimal from ResultSet.
Gets Boolean from ResultSet.
Gets Boolean from ResultSet.
Gets Instant from ResultSet.
Gets Instant from ResultSet.
Gets LocalDate from ResultSet.
Gets LocalDate from ResultSet.
Gets LocalDateTime from ResultSet.
Gets LocalDateTime from ResultSet.
Gets LocalTime from ResultSet.
Gets LocalTime from ResultSet.
Gets Timestamp from ResultSet.
Gets Timestamp from ResultSet.
Gets value from ResultSet.
Gets value from ResultSet.
- See also:
ResultSetMethods
Gets value by index from ResultSet.
Gets value by index from ResultSet.
- See also:
GetValueByLabel, ResultSetMethods
Gets value by label from ResultSet.
Gets value by label from ResultSet.
- See also:
GetValueByIndex, ResultSetMethods
Provides factory methods for InParam.
Provides factory methods for InParam.
- Companion:
- class
Provides extension methods for java.sql.PreparedStatement
.
Provides extension methods for java.sql.PreparedStatement
.
- See also:
StatementMethods
Represents result of query.
Represents result of query.
- Value parameters:
- resultSet
result set
- See also:
Provides interface to incrementally build and execute SQL statements.
Provides interface to incrementally build and execute SQL statements.
import java.sql.Connection
import scala.language.implicitConversions
import little.sql.{ *, given }
implicit val conn: Connection = ???
QueryBuilder("select * from users where group = ? and enabled = ?")
.params("staff", true) // Set input parameter values
.maxRows(10) // Limit result set to 10 rows
.foreach { rs => printf(s"uid=%d%n", rs.getInt("id")) } // Use implicit connection
// Same as above except use map of 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")) }
- Companion:
- object
Provides extension methods for java.sql.ResultSet
.
Provides extension methods for java.sql.ResultSet
.
Provides extension methods for java.sql.Statement
.
Provides extension methods for java.sql.Statement
.
- See also:
PreparedStatementMethods
Represents result of update.
Represents result of update.
- Value parameters:
- count
update count
- See also:
Converts Any to InParam.
Converts Any to InParam.
Converts BigDecimal to InParam.
Converts BigDecimal to InParam.
Converts Boolean to InParam.
Converts Boolean to InParam.
Converts Byte to InParam.
Converts Byte to InParam.
Converts Date to InParam.
Converts Date to InParam.
Converts Double to InParam.
Converts Double to InParam.
Converts Float to InParam.
Converts Float to InParam.
Converts Instant to InParam.
Converts Instant to InParam.
Converts Int to InParam.
Converts Int to InParam.
Converts LocalDateTime to InParam.
Converts LocalDateTime to InParam.
Converts LocalDate to InParam.
Converts LocalDate to InParam.
Converts LocalTime to InParam.
Converts LocalTime to InParam.
Converts Long to InParam.
Converts Long to InParam.
Converts Short to InParam.
Converts Short to InParam.
Converts String to InParam.
Converts String to InParam.
Converts Time to InParam.
Converts Time to InParam.
Converts Timestamp to InParam.
Converts Timestamp to InParam.
Givens
Givens
Implicits
Implicits
Provides extension methods for java.sql.Connection
.
Provides extension methods for java.sql.Connection
.
import scala.language.implicitConversions
import little.sql.{ *, given }
val connector = Connector("jdbc:h2:~/test", "sa", "s3cr3t", "org.h2.Driver")
connector.withConnection { conn =>
val statements = Seq(
"drop table prog_lang if exists",
"create table prog_lang (id int, name text)",
"insert into prog_lang (id, name) values (1, 'basic'), (2, 'pascal'), (3, 'c')",
"select * from prog_lang"
)
statements.foreach { sql =>
// Execute SQL and handle execution result accordingly
conn.execute(sql) {
// If update is executed print update count
case Update(count) ⇒ println(s"Update Count: $count")
// If query is executed print values of each row in ResultSet
case Query(resultSet) =>
while (resultSet.next())
printf("id: %d, name: %s%n", resultSet.getInt("id"), resultSet.getString("name"))
}
}
}
Provides extension methods for javax.sql.DataSource
.
Provides extension methods for javax.sql.DataSource
.
Provides extension methods for java.sql.PreparedStatement
.
Provides extension methods for java.sql.PreparedStatement
.
- See also:
StatementMethods
Provides extension methods for java.sql.ResultSet
.
Provides extension methods for java.sql.ResultSet
.