little.sql

package little.sql

Members list

Type members

Classlikes

final implicit class ConnectionMethods(connection: Connection) extends AnyVal

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 result set
     case Query(resultSet) =>
       while (resultSet.next())
         printf("id: %d, name: %s%n", resultSet.getInt("id"), resultSet.getString("name"))
   }
 }
}

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
class Connector(url: String, user: String, password: String, driverClassName: String, driverClassLoader: ClassLoader) extends DataSource

Defines data source connector.

Defines data source connector.

Value parameters

driverClassLoader

JDBC driver class loader

driverClassName

JDBC driver class name

password

data source password

url

data source url

user

data source user

Attributes

Supertypes
trait DataSource
trait Wrapper
trait CommonDataSource
class Object
trait Matchable
class Any
Show all
final implicit class DataSourceMethods(dataSource: DataSource) extends AnyVal

Provides extension methods for javax.sql.DataSource.

Provides extension methods for javax.sql.DataSource.

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
sealed abstract class Execution

Represents result of either update or query.

Represents result of either update or query.

If update, the result is count; otherwise, the execution is a query with resultSet.

Attributes

See also
Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
class Query
class Update
object Execution

Provides factory methods for Execution.

Provides factory methods for Execution.

Attributes

Companion
class
Supertypes
trait Sum
trait Mirror
class Object
trait Matchable
class Any
Self type
Execution.type
trait GetValue[T] extends GetValueByIndex[T], GetValueByLabel[T]

Gets value from ResultSet.

Gets value from ResultSet.

Attributes

See also

ResultSetMethods

Supertypes
trait GetValueByLabel[T]
trait GetValueByIndex[T]
class Object
trait Matchable
class Any
trait GetValueByIndex[T]

Gets value by index from ResultSet.

Gets value by index from ResultSet.

Attributes

See also

GetValueByLabel, ResultSetMethods

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait GetValue[T]
trait GetValueByLabel[T]

Gets value by label from ResultSet.

Gets value by label from ResultSet.

Attributes

See also

GetValueByIndex, ResultSetMethods

Supertypes
class Object
trait Matchable
class Any
Known subtypes
trait GetValue[T]
trait InParam

Defines value for input parameter.

Defines value for input parameter.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
Known subtypes
object Null.type
object InParam

Provides factory methods for InParam.

Provides factory methods for InParam.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
InParam.type
final implicit class PreparedStatementMethods(statement: PreparedStatement) extends AnyVal

Provides extension methods for java.sql.PreparedStatement.

Provides extension methods for java.sql.PreparedStatement.

Attributes

See also

StatementMethods

Supertypes
class AnyVal
trait Matchable
class Any
final case class Query(resultSet: ResultSet) extends Execution

Represents query execution.

Represents query execution.

Value parameters

resultSet

result set

Attributes

See also
Supertypes
trait Serializable
trait Product
trait Equals
class Execution
class Object
trait Matchable
class Any
Show all
trait QueryBuilder

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 }

given Connection = ???

// Set parameters and execute query
QueryBuilder("select * from users where group = ? and enabled = ?")
 .params("staff", true)
 .maxRows(10)
 .foreach { rs => printf(s"uid=%d%n", rs.getInt("id")) }

// Same as above except use mapped 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")) }

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object QueryBuilder

Provides QueryBuilder factory.

Provides QueryBuilder factory.

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
final implicit class ResultSetMethods(resultSet: ResultSet) extends AnyVal

Provides extension methods for java.sql.ResultSet.

Provides extension methods for java.sql.ResultSet.

Attributes

Supertypes
class AnyVal
trait Matchable
class Any
final implicit class StatementMethods(statement: Statement) extends AnyVal

Provides extension methods for java.sql.Statement.

Provides extension methods for java.sql.Statement.

Attributes

See also

PreparedStatementMethods

Supertypes
class AnyVal
trait Matchable
class Any
final case class Update(count: Long) extends Execution

Represents update execution.

Represents update execution.

Value parameters

count

update count

Attributes

See also
Supertypes
trait Serializable
trait Product
trait Equals
class Execution
class Object
trait Matchable
class Any
Show all

Givens

Givens

given anyToInParam: Conversion[Any, InParam]

Converts Any to InParam.

Converts Any to InParam.

Attributes

given bigDecimalToInParam: Conversion[BigDecimal, InParam]

Converts BigDecimal to InParam.

Converts BigDecimal to InParam.

Attributes

given booleanToInParam: Conversion[Boolean, InParam]

Converts Boolean to InParam.

Converts Boolean to InParam.

Attributes

given byteToInParam: Conversion[Byte, InParam]

Converts Byte to InParam.

Converts Byte to InParam.

Attributes

given dateToInParam: Conversion[Date, InParam]

Converts Date to InParam.

Converts Date to InParam.

Attributes

given doubleToInParam: Conversion[Double, InParam]

Converts Double to InParam.

Converts Double to InParam.

Attributes

given floatToInParam: Conversion[Float, InParam]

Converts Float to InParam.

Converts Float to InParam.

Attributes

Gets BigDecimal from ResultSet using index.

Gets BigDecimal from ResultSet using index.

Attributes

Gets BigDecimal from ResultSet using label.

Gets BigDecimal from ResultSet using label.

Attributes

Gets Boolean from ResultSet using index.

Gets Boolean from ResultSet using index.

Attributes

Gets Boolean from ResultSet using label.

Gets Boolean from ResultSet using label.

Attributes

Gets Byte from ResultSet using index.

Gets Byte from ResultSet using index.

Attributes

Gets Byte from ResultSet using label.

Gets Byte from ResultSet using label.

Attributes

Gets Date from ResultSet using index.

Gets Date from ResultSet using index.

Attributes

Gets Date from ResultSet using label.

Gets Date from ResultSet using label.

Attributes

Gets Double from ResultSet using index.

Gets Double from ResultSet using index.

Attributes

Gets Double from ResultSet using label.

Gets Double from ResultSet using label.

Attributes

Gets Float from ResultSet using index.

Gets Float from ResultSet using index.

Attributes

Gets Float from ResultSet using label.

Gets Float from ResultSet using label.

Attributes

Gets Instant from ResultSet using index.

Gets Instant from ResultSet using index.

Attributes

Gets Instant from ResultSet using label.

Gets Instant from ResultSet using label.

Attributes

Gets Int from ResultSet using index.

Gets Int from ResultSet using index.

Attributes

Gets Int from ResultSet using label.

Gets Int from ResultSet using label.

Attributes

Gets LocalDate from ResultSet using index.

Gets LocalDate from ResultSet using index.

Attributes

Gets LocalDate from ResultSet using label.

Gets LocalDate from ResultSet using label.

Attributes

Gets LocalDateTime from ResultSet using index.

Gets LocalDateTime from ResultSet using index.

Attributes

Gets LocalDateTime from ResultSet using label.

Gets LocalDateTime from ResultSet using label.

Attributes

Gets LocalTime from ResultSet using index.

Gets LocalTime from ResultSet using index.

Attributes

Gets LocalTime from ResultSet using label.

Gets LocalTime from ResultSet using label.

Attributes

Gets Long from ResultSet using index.

Gets Long from ResultSet using index.

Attributes

Gets Long from ResultSet using label.

Gets Long from ResultSet using label.

Attributes

Gets Short from ResultSet using index.

Gets Short from ResultSet using index.

Attributes

Gets Short from ResultSet using label.

Gets Short from ResultSet using label.

Attributes

Gets String from ResultSet using index.

Gets String from ResultSet using index.

Attributes

Gets String from ResultSet using label.

Gets String from ResultSet using label.

Attributes

Gets Time from ResultSet using index.

Gets Time from ResultSet using index.

Attributes

Gets Time from ResultSet using label.

Gets Time from ResultSet using label.

Attributes

Gets Timestamp from ResultSet using index.

Gets Timestamp from ResultSet using index.

Attributes

Gets Timestamp from ResultSet using label.

Gets Timestamp from ResultSet using label.

Attributes

given instantToInParam: Conversion[Instant, InParam]

Converts Instant to InParam.

Converts Instant to InParam.

Attributes

given intToInParam: Conversion[Int, InParam]

Converts Int to InParam.

Converts Int to InParam.

Attributes

given localDateTimeToInParam: Conversion[LocalDateTime, InParam]

Converts LocalDateTime to InParam.

Converts LocalDateTime to InParam.

Attributes

given localDateToInParam: Conversion[LocalDate, InParam]

Converts LocalDate to InParam.

Converts LocalDate to InParam.

Attributes

given localTimeToInParam: Conversion[LocalTime, InParam]

Converts LocalTime to InParam.

Converts LocalTime to InParam.

Attributes

given longToInParam: Conversion[Long, InParam]

Converts Long to InParam.

Converts Long to InParam.

Attributes

given mapToMapInParam[T](using convert: Conversion[T, InParam]): mapToMapInParam[T]

Converts Map[String, T] to Seq[String, InParam].

Converts Map[String, T] to Seq[String, InParam].

Attributes

given noneToInParam: Conversion[None.type, InParam]

Converts None to InParam.

Converts None to InParam.

Attributes

given optionToInParam[T](using convert: Conversion[T, InParam]): optionToInParam[T]

Converts Option[T] to InParam.

Converts Option[T] to InParam.

Attributes

given seqToSeqInParam[T](using convert: Conversion[T, InParam]): seqToSeqInParam[T]

Converts Seq[T] to Seq[InParam].

Converts Seq[T] to Seq[InParam].

Attributes

given shortToInParam: Conversion[Short, InParam]

Converts Short to InParam.

Converts Short to InParam.

Attributes

given stringToInParam: Conversion[String, InParam]

Converts String to InParam.

Converts String to InParam.

Attributes

given timeToInParam: Conversion[Time, InParam]

Converts Time to InParam.

Converts Time to InParam.

Attributes

given timestampToInParam: Conversion[Timestamp, InParam]

Converts Timestamp to InParam.

Converts Timestamp to InParam.

Attributes

given tupleToTupleInParam[T](using convert: Conversion[T, InParam]): tupleToTupleInParam[T]

Converts (String, T) to (String, InParam).

Converts (String, T) to (String, InParam).

Attributes

Implicits

Implicits

final implicit def ConnectionMethods(connection: Connection): ConnectionMethods

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 result set
     case Query(resultSet) =>
       while (resultSet.next())
         printf("id: %d, name: %s%n", resultSet.getInt("id"), resultSet.getString("name"))
   }
 }
}

Attributes

final implicit def DataSourceMethods(dataSource: DataSource): DataSourceMethods

Provides extension methods for javax.sql.DataSource.

Provides extension methods for javax.sql.DataSource.

Attributes

final implicit def PreparedStatementMethods(statement: PreparedStatement): PreparedStatementMethods

Provides extension methods for java.sql.PreparedStatement.

Provides extension methods for java.sql.PreparedStatement.

Attributes

See also

StatementMethods

final implicit def ResultSetMethods(resultSet: ResultSet): ResultSetMethods

Provides extension methods for java.sql.ResultSet.

Provides extension methods for java.sql.ResultSet.

Attributes

final implicit def StatementMethods(statement: Statement): StatementMethods

Provides extension methods for java.sql.Statement.

Provides extension methods for java.sql.Statement.

Attributes

See also

PreparedStatementMethods