Returns a list of entity objects (T's) created from executing the sql asynchronously
Returns a list of entity objects (T's) created from executing the sql asynchronously
the sql and arguments to execute, formed from SqlInterpolation
implicit function to transform the RowData to a T
implicit configuration settings
Example:
val price = 33.99 val books = exec[Book](q"select * from book where retail_price > $price") val aBook = execOne[Book](q"select * from '$table where '$column = $price") val prices = List(33.99, 14.52) val moreBooks = exec[Book](q"select * from book where retail_price in ($prices) order by book_id")
Returns a list of T's created from executing the sql asynchronously
Returns a list of T's created from executing the sql asynchronously
the sql to execute
the arguments for the query
implicit function to transform the RowData to a T
implicit configuration settings
Example:
val books = exec[Book]("select * from book") val allTitles = DbAsync.exec[String]("select title from book order by book_id")(r => r(0).toString, dbAsyncConfig)
Version of execNonQuery which takes a query interpolation generated query
Version of execNonQuery which takes a query interpolation generated query
Example:
val id = 123 execNonQuery[Book](q"delete from book where book_id = $id")
Asynchronously executes query, no results are expected
Asynchronously executes query, no results are expected
A Future[QueryResult] is returned, this is so that you can wait on the completion of the query if required.
the sql to execute
the arguments for the query
implicit configuration settings
returns a QueryResult, don't expect callers will use this apart from to wait on the result if they need to wait until the query has executed
Example:
execNonQuery[Book]("delete from book where book_id = 123") // example of stalling until query executes async { await(execNonQuery[Book]("delete from book where book_id = 123")) // code here won't continue until delete has been executed }
Version of execOne which expects a query generated from the query interpolation
Version of execOne which expects a query generated from the query interpolation
Example:
val bookId = 123 val noBookId = -1 val book = execOne[Book](q"select * from book where book_id = $bookId") // Book val book = execOne[Book](q"select * from book where book_id = $noBookId") // Exception -- no result val book = execOne[Book](q"select * from book") // Exception -- too many results
Asynchronously returns T containing single result from the query
Asynchronously returns T containing single result from the query
If more than one result or no result then throws exception.
the sql to execute
the arguments for the query
implicit function to transform the RowData to a T
implicit configuration settings
Example:
val book = execOne[Book]("select * from book where book_id = 123") // Book val book = execOne[Book]("select * from book where book_id = -1") // Exception -- no result val book = execOne[Book]("select * from book") // Exception -- too many results
Returns one or zero results from executing the query.
Returns one or zero results from executing the query. Designed to be called from a queryInterpolated string
type of the entity objects expected to be returned
result from a querty Interpolated string i.e. q"some query"
implicit function to convert sql RowData into the entity object T
implicit configuration settings
Some(Entity Object) or None -- throws exception if more than one row is found
Example:
val price = 33.44 val book = execOneOrNone[Book](q"select * from book where retail_price = $price") // Some() val book = execOneOrNone[Book](q"select * from book where book_id = -1") // None val book = execOneOrNone[Book](q"select * from book") // Exception -- too many results
Asynchronously returns Option[T] containing Some single result from the query or None if there were no results.
Asynchronously returns Option[T] containing Some single result from the query or None if there were no results.
If more than one result then throws exception.
type of the entity objects expected to be returned
the sql to execute
the arguments for the query
implicit function to convert sql RowData into the entity object T
implicit configuration settings
Some(Entity Object) or None -- throws exception if more than one row is found
Example:
val book = execOneOrNone[Book]("select * from book where book_id = 123") // Some() val book = execOneOrNone[Book]("select * from book where book_id = -1") // None val book = execOneOrNone[Book]("select * from book") // Exception -- too many results
Explicitly close down the database connections, releasing any resources.
Explicitly close down the database connections, releasing any resources.
Not a big deal to do, will happen automatically in most instances when app closes.
DbAsync is the main entry point for executing queries.
All queries are executed asynchronously
Example:
The public methods expect two implicit parameters: param f This is a function to convert from the returned database row, of type RowData to the entity object T. DbCodeGenerator.rowToClass will generate a function at compile time using a Scala Macros. Or you can hand craft the function. param config This contains the configuration used by dbmapper to connect to the database, and details of what to log. import com.github.njeuk.dbmapper.Implicits._ will place a default config in scope, which reads the db connection string from the application.conf settings. Or you can create your own specific settings as can be seen in the sample's attached to this project