Expandable is a trait for SQL queries that can be expanded.
Expandable is a trait for SQL queries that can be expanded.
It defines two expansion methods:
These methods should be called in the expand method.
import com.lucidchart.open.relate._ import com.lucidchart.open.relate.Query._ val ids = Array(1L, 2L, 3L) SQL(""" SELECT * FROM users WHERE id IN ({ids}) """).expand { implicit query => commaSeparated("ids", ids.size) }.on { longs("ids", ids) }
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.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")) })
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.
A smart wrapper around the PreparedStatement class that allows inserting parameter values by name rather than by index.
A smart wrapper around the PreparedStatement class that allows inserting parameter values by name rather than by index. Provides methods for inserting all necessary datatypes.
This class is used to insert tuple data into a prepared statement
A RowParser is a function that takes a SqlResult as a parameter and parses it to return a concrete type
A RowParser is a function that takes a SqlResult as a parameter and parses it to return a concrete type
See the RowParser for more information
(Since version 1.7.0) Use plain SqlResult => A instead
The PaginatedQuery companion object supplies apply methods that will create new PaginatedQuery's and execute them to get Streams of results.
The PaginatedQuery companion object supplies apply methods that will create new PaginatedQuery's and execute them to get Streams of results.
PaginatedQuery provides two pagination methods:
The latter method is provided because the LIMIT/OFFSET method has poor performance when result sets get large.
Provide implicit method calls for syntactic sugar
Provide implicit method calls for syntactic sugar
These functions should be used in the on and expand methods.
import com.lucidchart.open.relate._ import com.lucidchart.open.relate.Query._ SQL("SELECT * FROM users WHERE id={id}").on { implicit query => long("id", 1L) }
See the Relate Wiki for more information.
The RowParser companion object allows creation of arbitrary RowParsers with its apply method.
The RowParser companion object allows creation of arbitrary RowParsers with its apply method.
import com.lucidchart.open.relate.RowParser val rowParser = (row: SqlResult) => (row.long("id"), row.string("name")) }
Create a SQL query with the provided statement
Create a SQL query with the provided statement
the SQL statement
val query = SQL("SELECT * FROM users")
The SqlResultTypes object provides syntactic sugar for RowParser creation.
The SqlResultTypes object provides syntactic sugar for RowParser creation.
import com.lucidchart.open.relate._ import com.lucidchart.open.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".
Relate API
Use the SQL method to start an SQL query