Class

anorm

SimpleSql

Related Doc: package anorm

Permalink

case class SimpleSql[T](sql: SqlQuery, params: Map[String, ParameterValue], defaultParser: RowParser[T], resultSetOnFirstRow: Boolean = false) extends Sql with Product with Serializable

Simple/plain SQL.

Source
SimpleSql.scala
Linear Supertypes
Serializable, Serializable, Product, Equals, Sql, WithResult, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. SimpleSql
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. Sql
  7. WithResult
  8. AnyRef
  9. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Instance Constructors

  1. new SimpleSql(sql: SqlQuery, params: Map[String, ParameterValue], defaultParser: RowParser[T], resultSetOnFirstRow: Boolean = false)

    Permalink

Value Members

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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Permalink
    Definition Classes
    AnyRef → Any
  4. def as[T](parser: ResultSetParser[T])(implicit connection: Connection): T

    Permalink

    Converts this query result as T, using parser.

    Converts this query result as T, using parser.

    parser

    the result parser

    Definition Classes
    WithResult
    See also

    #asTry

  5. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  6. def asTry[T](parser: ResultSetParser[T], aliaser: ColumnAliaser = ColumnAliaser.empty)(implicit connection: Connection): Try[T]

    Permalink

    Converts this query result as T, using parser.

    Converts this query result as T, using parser.

    parser

    the result parser

    aliaser

    the column aliaser

    Definition Classes
    WithResult
  7. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  8. val defaultParser: RowParser[T]

    Permalink
  9. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  10. def execute()(implicit connection: Connection): Boolean

    Permalink

    Executes this SQL statement.

    Executes this SQL statement.

    returns

    true if resultset was returned from execution (statement is query), or false if it executed update.

    val res: Boolean =
      SQL"""INSERT INTO Test(a, b) VALUES(\${"A"}, \${"B"}""".execute()
    Definition Classes
    Sql
  11. def executeInsert[A](generatedKeysParser: ResultSetParser[A] = SqlParser.scalar[Long].singleOpt)(implicit connection: Connection): A

    Permalink

    Executes this SQL as an insert statement.

    Executes this SQL as an insert statement.

    generatedKeysParser

    Parser for generated key (default: scalar long)

    returns

    Parsed generated keys

    import anorm.SqlParser.scalar
    val keys1 = SQL("INSERT INTO Test(x) VALUES ({x})").
      on("x" -> "y").executeInsert()
    val keys2 = SQL("INSERT INTO Test(x) VALUES ({x})").
      on("x" -> "y").executeInsert(scalar[String].singleOpt)
    // ... generated string key
    Definition Classes
    Sql
  12. def executeInsert1[A](generatedColumn: String, otherColumns: String*)(generatedKeysParser: ResultSetParser[A] = SqlParser.scalar[Long].singleOpt)(implicit connection: Connection): Try[A]

    Permalink

    Executes this SQL as an insert statement.

    Executes this SQL as an insert statement.

    generatedColumn

    the first (mandatory) column name to consider from the generated keys

    otherColumns

    the other (possibly none) column name(s) from the generated keys

    generatedKeysParser

    the parser for generated key (default: scalar long)

    returns

    Parsed generated keys

    import anorm.SqlParser.scalar
    val keys1 = SQL("INSERT INTO Test(x) VALUES ({x})").
      on("x" -> "y").executeInsert1("generatedCol", "colB")()
    val keys2 = SQL("INSERT INTO Test(x) VALUES ({x})").
      on("x" -> "y").executeInsert1("generatedCol")(scalar[String].singleOpt)
    // ... generated string key
    Definition Classes
    Sql
  13. def executeInsert2[A](generatedColumn: String, otherColumns: String*)(generatedKeysParser: ResultSetParser[A] = SqlParser.scalar[Long].singleOpt, aliaser: ColumnAliaser)(implicit connection: Connection): Try[A]

    Permalink

    Executes this SQL as an insert statement.

    Executes this SQL as an insert statement.

    generatedColumn

    the first (mandatory) column name to consider from the generated keys

    otherColumns

    the other (possibly none) column name(s) from the generated keys

    generatedKeysParser

    the parser for generated key (default: scalar long)

    aliaser

    the column aliaser

    returns

    Parsed generated keys

    import anorm.SqlParser.scalar
    val keys1 = SQL("INSERT INTO Test(x) VALUES ({x})").
      on("x" -> "y").executeInsert1("generatedCol", "colB")()
    val keys2 = SQL("INSERT INTO Test(x) VALUES ({x})").
      on("x" -> "y").executeInsert1("generatedCol")(scalar[String].singleOpt)
    // ... generated string key
    Definition Classes
    Sql
  14. def executeQuery()(implicit connection: Connection): SqlQueryResult

    Permalink

    Executes this SQL query, and returns its result.

    Executes this SQL query, and returns its result.

    implicit val conn: Connection = openConnection
    val res: SqlQueryResult =
      SQL("SELECT text_col FROM table WHERE id = {code}").
      on("code" -> code).executeQuery()
    // Check execution context; e.g. res.statementWarning
    val str = res as scalar[String].single // going with row parsing
    Definition Classes
    Sql
  15. def executeUpdate()(implicit connection: Connection): Int

    Permalink

    Executes this SQL as an update statement.

    Executes this SQL as an update statement.

    returns

    Count of updated row(s)

    Definition Classes
    Sql
    Annotations
    @throws( "If statement is query not update" )
  16. def fetchSize: Option[Int]

    Permalink

    Fetch size

  17. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. def fold[T](z: ⇒ T, aliaser: ColumnAliaser)(op: (T, Row) ⇒ T)(implicit connection: Connection): Either[List[Throwable], T]

    Permalink

    Aggregates over all rows using the specified operator.

    Aggregates over all rows using the specified operator.

    z

    the start value

    aliaser

    the column aliaser

    op

    Aggregate operator

    returns

    Either list of failures at left, or aggregated value

    Definition Classes
    WithResult
    See also

    #withResult

    #foldWhile

  19. def foldWhile[T](z: ⇒ T, aliaser: ColumnAliaser)(op: (T, Row) ⇒ (T, Boolean))(implicit connection: Connection): Either[List[Throwable], T]

    Permalink

    Aggregates over part of or the while row stream, using the specified operator.

    Aggregates over part of or the while row stream, using the specified operator.

    z

    the start value

    aliaser

    the column aliaser

    op

    Aggregate operator. Returns aggregated value along with true if aggregation must process next value, or false to stop with current value.

    returns

    Either list of failures at left, or aggregated value

    Definition Classes
    WithResult
    See also

    #withResult

  20. final def getClass(): Class[_]

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

    Permalink
    Definition Classes
    Any
  22. def map[A](f: (T) ⇒ A): SimpleSql[A]

    Permalink
  23. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. def on(args: NamedParameter*): SimpleSql[T]

    Permalink

    Returns query prepared with named parameters.

    Returns query prepared with named parameters.

    import anorm.toParameterValue
    
    val baseSql = SQL("SELECT * FROM table WHERE id = {id}") // one named param
    val preparedSql = baseSql.withParams("id" -> "value")
  27. def onParams(args: ParameterValue*): SimpleSql[T]

    Permalink

    Returns query prepared with parameters using initial order of placeholder in statement.

    Returns query prepared with parameters using initial order of placeholder in statement.

    import anorm.toParameterValue
    
    val baseSql =
      SQL("SELECT * FROM table WHERE name = {name} AND lang = {lang}")
    
    val preparedSql = baseSql.onParams("1st", "2nd")
    // 1st param = name, 2nd param = lang
  28. val params: Map[String, ParameterValue]

    Permalink
  29. def preparedStatement(connection: Connection, generatedColumn: String, generatedColumns: Seq[String]): ManagedResource[PreparedStatement]

    Permalink
    Definition Classes
    SimpleSql → Sql
  30. def preparedStatement(connection: Connection, getGeneratedKeys: Boolean = false): ManagedResource[PreparedStatement]

    Permalink
    Definition Classes
    SimpleSql → Sql
  31. def resultSet(connection: Connection): ManagedResource[ResultSet]

    Permalink

    Executes this statement as query (see executeQuery) and returns result.

    Executes this statement as query (see executeQuery) and returns result.

    Attributes
    protected
    Definition Classes
    Sql → WithResult
  32. val resultSetOnFirstRow: Boolean

    Permalink

    ResultSet is initialized on first row (JDBC degraded)

    ResultSet is initialized on first row (JDBC degraded)

    Definition Classes
    SimpleSql → WithResult
  33. val sql: SqlQuery

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

    Permalink
    Definition Classes
    AnyRef
  35. final def wait(): Unit

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

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

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  38. def withFetchSize(count: Option[Int]): SimpleSql[T]

    Permalink

    Returns this query with the fetch suze updated to the row count.

    Returns this query with the fetch suze updated to the row count.

    See also

    SqlQuery.fetchSize

  39. def withQueryTimeout(seconds: Option[Int]): SimpleSql[T]

    Permalink

    Returns a copy with updated timeout.

  40. def withResult[T](op: (Option[Cursor]) ⇒ T, aliaser: ColumnAliaser)(implicit connection: Connection): Either[List[Throwable], T]

    Permalink

    Processes all or some rows from current result.

    Processes all or some rows from current result.

    op

    Operation applied with row cursor

    @annotation.tailrec
    def go(c: Option[Cursor], l: List[Row]): List[Row] = c match {
      case Some(cursor) => go(cursor.next, l :+ cursor.row)
      case _ => l
    }
    val l: Either[List[Throwable], List[Row]] =
      SQL"SELECT * FROM Test".withResult(go)
    Definition Classes
    WithResult
  41. def withResult[T](op: (Option[Cursor]) ⇒ T)(implicit connection: Connection): Either[List[Throwable], T]

    Permalink

    Processes all or some rows from current result.

    Processes all or some rows from current result.

    op

    Operation applied with row cursor

    Definition Classes
    WithResult
  42. def withResultSetOnFirstRow(onFirst: Boolean): SimpleSql[T]

    Permalink

    Returns a copy with updated flag.

Deprecated Value Members

  1. def fold[T](z: ⇒ T)(op: (T, Row) ⇒ T)(implicit connection: Connection): Either[List[Throwable], T]

    Permalink

    Aggregates over all rows using the specified operator.

    Aggregates over all rows using the specified operator.

    z

    the start value

    op

    Aggregate operator

    returns

    Either list of failures at left, or aggregated value

    Definition Classes
    WithResult
    Annotations
    @deprecated
    Deprecated

    (Since version 2.5.1) Use fold with empty ColumnAliaser

    See also

    #withResult

    #foldWhile

  2. def foldWhile[T](z: ⇒ T)(op: (T, Row) ⇒ (T, Boolean))(implicit connection: Connection): Either[List[Throwable], T]

    Permalink

    Aggregates over part of or the while row stream, using the specified operator.

    Aggregates over part of or the while row stream, using the specified operator.

    z

    the start value

    op

    Aggregate operator. Returns aggregated value along with true if aggregation must process next value, or false to stop with current value.

    returns

    Either list of failures at left, or aggregated value

    Definition Classes
    WithResult
    Annotations
    @deprecated
    Deprecated

    (Since version 2.5.1) Use foldWhile with empty ColumnAliaser

    See also

    #withResult

  3. def using[U](p: RowParser[U]): SimpleSql[U]

    Permalink

    Prepares query with given row parser.

    Prepares query with given row parser.

    import anorm.{ SQL, SqlParser }
    
    val res: Int = SQL("SELECT 1").using(SqlParser.scalar[Int]).single
    // Equivalent to: SQL("SELECT 1").as(SqlParser.scalar[Int].single)
    Annotations
    @deprecated
    Deprecated

    (Since version 2.5.1) Use as

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from Sql

Inherited from WithResult

Inherited from AnyRef

Inherited from Any

Ungrouped