zquery
package zquery
- Alphabetic
- Public
- All
Type Members
-
class
Cache extends AnyRef
A
Cache
maintains an internal state with a mapping from requests toRef
s that will contain the result of those requests when they are executed.A
Cache
maintains an internal state with a mapping from requests toRef
s that will contain the result of those requests when they are executed. This is used internally by the library to provide deduplication and caching of requests. -
final
class
CompletedRequestMap extends AnyRef
A
CompletedRequestMap
is a universally quantified mapping from requests of typeRequest[E, A]
to results of typeEither[E, A[
for all typesE
andA
.A
CompletedRequestMap
is a universally quantified mapping from requests of typeRequest[E, A]
to results of typeEither[E, A[
for all typesE
andA
. The guarantee is that for any request of typeRequest[E, A]
, if there is a corresponding value in the map, that value is of typeEither[E, A]
. This is used by the library to support data sources that return different result types for different requests while guaranteeing that results will be of the type requested. -
trait
DataSource[-R, -A] extends AnyRef
A
DataSource[R, A]
is capable of executing requests of typeA
that require an environmentR
.A
DataSource[R, A]
is capable of executing requests of typeA
that require an environmentR
.Data sources must implement the method
run
which takes a collection of requests and returns an effect with aCompletedRequestMap
containing a mapping from requests to results. Becauserun
is parameterized on a collection of requests rather than a single request, data sources have the ability to introspect on all the requests being executed in parallel and optimize the query.Data sources will typically be parameterized on a subtype of
Request[A]
, though that is not strictly necessarily as long as the data source can map the request type to aRequest[A]
. Data sources can then pattern match on the collection of requests to determine the information requested, execute the query, and place the results into theCompletedRequestsMap
using CompletedRequestMap.empty and CompletedRequestMap.insert. Data sources must provide requests for all results received or fail with anE
. Failure to do so will cause a query to die with aQueryFailure
when run. -
trait
DataSourceFunction[+R, -R1] extends AnyRef
A
DataSourceFunction[R, R1]
is a universally quantified function from values of typeDataSource[R, A]
to values of typeDataSource[R1, A]
for all typesA
.A
DataSourceFunction[R, R1]
is a universally quantified function from values of typeDataSource[R, A]
to values of typeDataSource[R1, A]
for all typesA
. This is used internally by the library to describe functions for transforming data sources that do not change the type of requests that a data source is able to execute. -
final
case class
QueryFailure(dataSource: Service[Nothing, Nothing], request: Request[Any, Any]) extends Throwable with Product with Serializable
QueryFailure
keeps track of details relevant to query failures. -
trait
Request[+E, +A] extends AnyRef
A
Request[E, A]
is a request from a data source for a value of typeA
that may fail with anE
.A
Request[E, A]
is a request from a data source for a value of typeA
that may fail with anE
.sealed trait UserRequest[+A] extends Request[Nothing, A] case object GetAllIds extends UserRequest[List[Int]] final case class GetNameById(id: Int) extends UserRequest[String]
-
sealed
trait
ZQuery[-R, +E, +A] extends AnyRef
A
ZQuery[R, E, A]
is a purely functional description of an effectual query that may contain requests from one or more data sources, requires an environmentR
, may fail with anE
, and may succeed with anA
.A
ZQuery[R, E, A]
is a purely functional description of an effectual query that may contain requests from one or more data sources, requires an environmentR
, may fail with anE
, and may succeed with anA
. All requests that do not need to be performed sequentially, as expressed byflatMap
or combinators derived from it, will automatically be batched, allowing for aggressive data source specific optimizations. Requests will also automatically be deduplicated and cached.This allows for writing queries in a high level, compositional style, with confidence that they will automatically be optimized. For example, consider the following query from a user service.
val getAllUserIds: ZQuery[Any, Nothing, List[Int]] = ??? def getUserNameById(id: Int): ZQuery[Any, Nothing, String] = ??? for { userIds <- getAllUserIds userNames <- ZQuery.foreachPar(userIds)(getUserNameById) } yield userNames
This would normally require N + 1 queries, one for
getAllUserIds
and one for each call togetUserNameById
. In contrast,ZQuery
will automatically optimize this to two queries, one foruserIds
and one foruserNames
, assuming an implementation of the user service that supports batching.Based on "There is no Fork: an Abstraction for Efficient, Concurrent, and Concise Data Access" by Simon Marlow, Louis Brandy, Jonathan Coens, and Jon Purdy. http://simonmar.github.io/bib/papers/haxl-icfp14.pdf
Value Members
- object BlockedRequestMap
- object Cache
- object CompletedRequestMap
- object DataSource
- object DataSourceFunction
- object ZQuery