com.lucidchart.open.relate

Sql

sealed trait Sql extends AnyRef

Sql is a trait for basic SQL queries.

It provides methods for parameter insertion and query execution.

import com.lucidchart.open.relate._
import com.lucidchart.open.relate.Query._

case class User(id: Long, name: String)

SQL("""
  SELECT id, name
  FROM users
  WHERE id={id}
""").on { implicit query =>
  long("id", 1L)
}.asSingle(RowParser { row =>
  User(row.long("id"), row.string("name"))
})
Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Sql
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Abstract Value Members

  1. abstract def getCopy(params: List[(SqlStatement) ⇒ Unit]): Sql

    Classes that inherit the Sql trait will have to implement a method to copy themselves given just a different set of parameters.

    Classes that inherit the Sql trait will have to implement a method to copy themselves given just a different set of parameters. HINT: Use a case class!

    Attributes
    protected
  2. abstract val listParams: Map[String, ListParam]

    A collection of list type parameters mapped to their names

  3. abstract val params: List[(SqlStatement) ⇒ Unit]

    A list of anonymous functions that insert parameters into a SqlStatement

  4. abstract val query: String

    The query string associated with the query

  5. abstract val queryParams: QueryParams

    The query, params, and listParams bundled together in a case class

Concrete 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. def asCollection[U, T[_]](parser: RowParser[U])(implicit cbf: CanBuildFrom[T[U], U, T[U]], connection: Connection): T[U]

    Execute this query and get back the result as an arbitrary collection of records

    Execute this query and get back the result as an arbitrary collection of records

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as an arbitrary collection of records

  7. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  8. def asIterable[A](parser: RowParser[A])(implicit connection: Connection): Iterable[A]

    Execute this query and get back the result as an iterable of records

    Execute this query and get back the result as an iterable of records

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as an iterable of records

  9. def asIterator[A](parser: RowParser[A], fetchSize: Int = 100)(implicit connection: Connection): Iterator[A]

    The asIterator method returns an Iterator that will stream data out of the database.

    The asIterator method returns an Iterator that will stream data out of the database. This avoids an OutOfMemoryError when dealing with large datasets. Bear in mind that many JDBC implementations will not allow additional queries to the connection before all records in the Iterator have been retrieved.

    parser

    the RowParser to parse rows with

    fetchSize

    the number of rows to fetch at a time, defaults to 100. If the JDBC Driver is MySQL, the fetchSize will always default to Int.MinValue, as MySQL's JDBC implementation ignores all other fetchSize values and only streams if fetchSize is Int.MinValue

  10. def asList[A](parser: RowParser[A])(implicit connection: Connection): List[A]

    Execute this query and get back the result as a List of records

    Execute this query and get back the result as a List of records

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as a List of records

  11. def asMap[U, V](parser: RowParser[(U, V)])(implicit connection: Connection): Map[U, V]

    Execute this query and get back the result as a Map of records

    Execute this query and get back the result as a Map of records

    parser

    the RowParser to use when parsing the result set. The RowParser should return a Tuple of size 2 containing the key and value

    connection

    the connection to use when executing the query

    returns

    the results as a Map of records

  12. def asPairCollection[U, V, T[_, _]](parser: RowParser[(U, V)])(implicit cbf: CanBuildFrom[T[U, V], (U, V), T[U, V]], connection: Connection): T[U, V]

    Execute this query and get back the result as an arbitrary collection of key value pairs

    Execute this query and get back the result as an arbitrary collection of key value pairs

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as an arbitrary collection of key value pairs

  13. def asScalar[A]()(implicit connection: Connection): A

    Execute this query and get back the result as a single value.

    Execute this query and get back the result as a single value. Assumes that there is only one row and one value in the result set.

    connection

    the connection to use when executing the query

    returns

    the results as a single value

  14. def asScalarOption[A]()(implicit connection: Connection): Option[A]

    Execute this query and get back the result as an optional single value.

    Execute this query and get back the result as an optional single value. Assumes that there is only one row and one value in the result set.

    connection

    the connection to use when executing the query

    returns

    the results as an optional single value

  15. def asSeq[A](parser: RowParser[A])(implicit connection: Connection): Seq[A]

    Execute this query and get back the result as a sequence of records

    Execute this query and get back the result as a sequence of records

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as a sequence of records

  16. def asSet[A](parser: RowParser[A])(implicit connection: Connection): Set[A]

    Execute this query and get back the result as a Set of records

    Execute this query and get back the result as a Set of records

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as a Set of records

  17. def asSingle[A](parser: RowParser[A])(implicit connection: Connection): A

    Execute this query and get back the result as a single record

    Execute this query and get back the result as a single record

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as a single record

  18. def asSingleOption[A](parser: RowParser[A])(implicit connection: Connection): Option[A]

    Execute this query and get back the result as an optional single record

    Execute this query and get back the result as an optional single record

    parser

    the RowParser to use when parsing the result set

    connection

    the connection to use when executing the query

    returns

    the results as an optional single record

  19. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  21. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  22. def execute()(implicit connection: Connection): Boolean

    Execute a statement

    Execute a statement

    connection

    the db connection to use when executing the query

    returns

    whether the query succeeded in its execution

  23. def executeInsertCollection[U, T[_]](parser: RowParser[U])(implicit cbf: CanBuildFrom[T[U], U, T[U]], connection: Connection): T[U]

    Execute the query and get the auto-incremented keys using a RowParser.

    Execute the query and get the auto-incremented keys using a RowParser. Provided for the case that a primary key is not an Int or BigInt

    parser

    the RowParser that can parse the returned keys

    connection

    the connection to use when executing the query

    returns

    the auto-incremented keys

  24. def executeInsertInt()(implicit connection: Connection): Int

    Execute the query and get the auto-incremented key as an Int

    Execute the query and get the auto-incremented key as an Int

    connection

    the connection to use when executing the query

    returns

    the auto-incremented key as an Int

  25. def executeInsertInts()(implicit connection: Connection): List[Int]

    Execute the query and get the auto-incremented keys as a List of Ints

    Execute the query and get the auto-incremented keys as a List of Ints

    connection

    the connection to use when executing the query

    returns

    the auto-incremented keys as a List of Ints

  26. def executeInsertLong()(implicit connection: Connection): Long

    Execute the query and get the auto-incremented key as a Long

    Execute the query and get the auto-incremented key as a Long

    connection

    the connection to use when executing the query

    returns

    the auto-incremented key as a Long

  27. def executeInsertLongs()(implicit connection: Connection): List[Long]

    Execute the query and get the auto-incremented keys as a a List of Longs

    Execute the query and get the auto-incremented keys as a a List of Longs

    connection

    the connection to use when executing the query

    returns

    the auto-incremented keys as a a List of Longs

  28. def executeInsertSingle[U](parser: RowParser[U])(implicit connection: Connection): U

    Execute the query and get the auto-incremented key using a RowParser.

    Execute the query and get the auto-incremented key using a RowParser. Provided for the case that a primary key is not an Int or BigInt

    parser

    the RowParser that can parse the returned key

    connection

    the connection to use when executing the query

    returns

    the auto-incremented key

  29. def executeUpdate()(implicit connection: Connection): Int

    Execute an update

    Execute an update

    connection

    the db connection to use when executing the query

    returns

    the number of rows update by the query

  30. def finalize(): Unit

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

    Definition Classes
    AnyRef → Any
  32. def hashCode(): Int

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

    Definition Classes
    Any
  34. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  35. final def notify(): Unit

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

    Definition Classes
    AnyRef
  37. def on(f: (SqlStatement) ⇒ Unit): Sql

    Put in values for parameters in the query

    Put in values for parameters in the query

    f

    a function that takes a SqlStatement and sets parameter values using its methods

    returns

    a copy of this Sql with the new params

  38. def onTuples[A](name: String, tuples: TraversableOnce[A])(f: (A, TupleStatement) ⇒ Unit): Sql

    Put in values for tuple parameters in the query

    Put in values for tuple parameters in the query

    name

    the tuple identifier in the query

    tuples

    the objects to loop over and use to insert data into the query

    f

    a function that takes a TupleStatement and sets parameter values using its methods

    returns

    a copy of this Sql with the new tuple params

  39. def results()(implicit connection: Connection): ResultSet

    Provides direct access to the underlying java.

    Provides direct access to the underlying java.sql.ResultSet. Note that this ResultSet must be closed manually or by wrapping it in SqlResult.

    val results = SQL(query).results()
    . . .
    SqlResult(results).asList[A](parser)
    // or
    results.close()
    returns

    java.sql.ResultSet

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

    Definition Classes
    AnyRef
  41. def toString(): String

    Definition Classes
    AnyRef → Any
  42. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped