Sql is a trait for basic SQL queries.
Sql is a trait for basic SQL queries.
It provides methods for parameter insertion and query execution.
import com.lucidchart.relate._ import com.lucidchart.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")) })
The SqlResult class is a wrapper around Java's ResultSet class.
The SqlResult class is a wrapper around Java's ResultSet class.
It provides methods to allows users to retrieve specific columns by name and datatype, but also provides methods that can, given a RowParser, parse the entire result set as a collection of records returned by the parser. These methods are also defined in the Sql trait, and are most conveniently used when chained with parameter insertion. For how to do this, see the Sql trait documentation.
The extraction methods (int, string, long, etc.) also have "strict" counterparts. The "strict" methods are slightly faster, but do not do type checking or handle null values.
The SqlResultTypes object provides syntactic sugar for RowParser creation.
The SqlResultTypes object provides syntactic sugar for RowParser creation.
import com.lucidchart.relate._ import com.lucidchart.relate.SqlResultTypes._ val rowParser = RowParser { implicit row => (long("id"), string("name")) }
In this example, declaring "row" as implicit precludes the need to explicitly use the long and string methods on "row".