package query
- Alphabetic
- By Inheritance
- query
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
trait
Cache extends AnyRef
A
Cachemaintains an internal state with a mapping from requests toRefs that will contain the result of those requests when they are executed.A
Cachemaintains an internal state with a mapping from requests toRefs 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
CompletedRequestMapis a universally quantified mapping from requests of typeRequest[E, A]to results of typeEither[E, A[for all typesEandA.A
CompletedRequestMapis a universally quantified mapping from requests of typeRequest[E, A]to results of typeEither[E, A[for all typesEandA. 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]requires an environmentRand is capable of executing requests of typeA.A
DataSource[R, A]requires an environmentRand is capable of executing requests of typeA.Data sources must implement the method
runAllwhich takes a collection of requests and returns an effect with aCompletedRequestMapcontaining a mapping from requests to results. The type of the collection of requests is aChunk[Chunk[A]]. The outerChunkrepresents batches of requests that must be performed sequentially. The innerChunkrepresents a batch of requests that can be performed in parallel. This allows data sources to introspect on all the requests being executed 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 theCompletedRequestsMapusing CompletedRequestMap.empty and CompletedRequestMap.insert. Data sources must provide results for all requests received. Failure to do so will cause a query to die with aQueryFailurewhen run. -
trait
DataSourceAspect[-R] extends AnyRef
A
DataSourceAspectis an aspect that can be weaved into queries.A
DataSourceAspectis an aspect that can be weaved into queries. You can think of an aspect as a polymorphic function, capable of transforming one data source into another, possibly enlarging the environment type. -
final
case class
Described[+A](value: A, description: String) extends Product with Serializable
A
Described[A]is a value of typeAalong with a string description of that value.A
Described[A]is a value of typeAalong with a string description of that value. The description may be used to generate a hash associated with the value, so values that are equal should have the same description and values that are not equal should have different descriptions. - type Query[+E, +A] = ZQuery[Any, E, A]
-
final
case class
QueryFailure(dataSource: DataSource[Nothing, Nothing], request: Request[Any, Any]) extends Throwable with Product with Serializable
QueryFailurekeeps track of details relevant to query failures. - type RQuery[-R, +A] = ZQuery[R, Throwable, A]
-
trait
Request[+E, +A] extends AnyRef
A
Request[E, A]is a request from a data source for a value of typeAthat may fail with anE.A
Request[E, A]is a request from a data source for a value of typeAthat 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]
- type TaskQuery[+A] = ZQuery[Any, Throwable, A]
- type UQuery[+A] = ZQuery[Any, Nothing, A]
- type URQuery[-R, +A] = ZQuery[R, Nothing, A]
-
final
class
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, and may fail with anEor 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, and may fail with anEor succeed with anA.Requests that can be performed in parallel, as expressed by
zipWithParand combinators derived from it, will automatically be batched. Requests that must be performed sequentially, as expressed byzipWithand combinators derived from it, will automatically be pipelined. This allows for aggressive data source specific optimizations. Requests can also 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
getAllUserIdsand one for each call togetUserNameById. In contrast,ZQuerywill automatically optimize this to two queries, one foruserIdsand 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 Cache
- object CompletedRequestMap
- object DataSource
- object DataSourceAspect
- object Described extends Serializable
- object ZQuery