Returns possibly empty list parsed from result.
Returns possibly empty list parsed from result.
val price = 125 SQL"SELECT name FROM item WHERE price < \$price".as(scalar[String].*)
Returns non empty list parse from result, or raise error if there is no result.
Returns non empty list parse from result, or raise error if there is no result.
import anorm.SQL import anorm.SqlParser.str val parser = str("title") ~ str("descr") SQL("SELECT title, descr FROM pages").as(parser.+) // at least 1 page
Combines this current parser with the one given as argument p
,
if and only if the current parser can first successfully
parse a row, without keeping the values of the parser p
.
Combines this current parser with the one given as argument p
,
if and only if the current parser can first successfully
parse a row, without keeping the values of the parser p
.
import anorm.{ SQL, SqlParser }, SqlParser.{ int, str } val Int = SQL("SELECT * FROM test"). as((int("id") <~ str("val")).single) // row has to have an int column 'id' and a string 'val' one, // keeping only 'id' in result
Alias for flatMap
Returns a row parser for optional column, that will turn missing or null column as None.
Returns a row parser for optional column, that will turn missing or null column as None.
Returns parser which collects information
from already parsed row data using f
.
Returns parser which collects information
from already parsed row data using f
.
Message returned as error if nothing can be collected using f
.
Collecting function
Returns a parser that will apply given function f
to the result of this first parser.
Returns a parser that will apply given function f
to the result of this first parser. If the current parser is not
successful, the new one will return encountered Error.
Function applied on the successful parser result
import anorm.{ RowParser, SQL, SqlParser } val parser: RowParser[Int] = SqlParser.str("col").map(_.length) // Prepares a parser that first get 'col' string value, // and then returns the length of that
Returns a result set parser expecting exactly one row to parse.
Returns a result set parser expecting exactly one row to parse.
val b: Boolean = SQL("SELECT flag FROM Test WHERE id = :id"). on("id" -> 1).as(scalar[Boolean].single)
#singleOpt
Returns a result set parser for none or one parsed row.
Returns a result set parser for none or one parsed row.
val name: Option[String] = SQL("SELECT name FROM Country WHERE lang = :lang") .on("lang" -> "notFound").as(scalar[String].singleOpt)
Combines this parser on the left of the parser p
given as argument.
Combines this parser on the left of the parser p
given as argument.
Parser on the right
val populations: List[String ~ Int] = SQL("SELECT * FROM Country").as((str("name") ~ int("population")).*)
Combines this current parser with the one given as argument p
,
if and only if the current parser can first/on left side successfully
parse a row, without keeping these values in parsed result.
Combines this current parser with the one given as argument p
,
if and only if the current parser can first/on left side successfully
parse a row, without keeping these values in parsed result.
import anorm.{ SQL, SqlParser }, SqlParser.{ int, str } val String = SQL("SELECT * FROM test"). as((int("id") ~> str("val")).single) // row has to have an int column 'id' and a string 'val' one, // keeping only 'val' in result
Parser for scalar row (row of one single column).