Class/Object

zio.zquery

ZQuery

Related Docs: object ZQuery | package zquery

Permalink

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 environment R, may fail with an E, and may succeed with an A. All requests that do not need to be performed sequentially, as expressed by flatMap 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 to getUserNameById. In contrast, ZQuery will automatically optimize this to two queries, one for userIds and one for userNames, 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

Self Type
ZQuery[R, E, A]
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ZQuery
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def &>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    A symbolic alias for zipParRight.

  4. final def *>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    A symbolic alias for zipRight.

  5. final def <&[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Permalink

    A symbolic alias for zipParLeft.

  6. final def <&>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Permalink

    A symbolic alias for zipPar.

  7. final def <*[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Permalink

    A symbolic alias for zipLeft.

  8. final def <*>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Permalink

    A symbolic alias for zip.

  9. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  10. final def >>=[R1 <: R, E1 >: E, B](f: (A) ⇒ ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    A symbolic alias for flatMap.

  11. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  12. final def bimap[E1, B](f: (E) ⇒ E1, g: (A) ⇒ B)(implicit ev: CanFail[E]): ZQuery[R, E1, B]

    Permalink

    Returns a query whose failure and success channels have been mapped by the specified pair of functions, f and g.

  13. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  14. final def either(implicit ev: CanFail[E]): ZQuery[R, Nothing, Either[E, A]]

    Permalink

    Returns a query whose failure and success have been lifted into an Either.

    Returns a query whose failure and success have been lifted into an Either. The resulting query cannot fail, because the failure case has been exposed as part of the Either success case.

  15. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  16. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  17. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  18. final def flatMap[R1 <: R, E1 >: E, B](f: (A) ⇒ ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    Returns a query that models execution of this query, followed by passing its result to the specified function that returns a query.

    Returns a query that models execution of this query, followed by passing its result to the specified function that returns a query. Requests composed with flatMap or combinators derived from it will be executed sequentially and will not be batched, though deduplication and caching of requests will still be applied.

  19. final def fold[B](failure: (E) ⇒ B, success: (A) ⇒ B)(implicit ev: CanFail[E]): ZQuery[R, Nothing, B]

    Permalink

    Folds over the failed or successful result of this query to yield a query that does not fail, but succeeds with the value returned by the left or right function passed to fold.

  20. final def foldCauseM[R1 <: R, E1, B](failure: (Cause[E]) ⇒ ZQuery[R1, E1, B], success: (A) ⇒ ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    A more powerful version of foldM that allows recovering from any type of failure except interruptions.

  21. final def foldM[R1 <: R, E1, B](failure: (E) ⇒ ZQuery[R1, E1, B], success: (A) ⇒ ZQuery[R1, E1, B])(implicit ev: CanFail[E]): ZQuery[R1, E1, B]

    Permalink

    Recovers from errors by accepting one query to execute for the case of an error, and one query to execute for the case of success.

  22. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  23. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  24. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  25. final def map[B](f: (A) ⇒ B): ZQuery[R, E, B]

    Permalink

    Maps the specified function over the successful result of this query.

  26. final def mapError[E1](f: (E) ⇒ E1)(implicit ev: CanFail[E]): ZQuery[R, E1, A]

    Permalink

    Maps the specified function over the failed result of this query.

  27. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  28. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  29. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  30. final def optional: ZQuery[R, E, Option[A]]

    Permalink

    Converts this query to one that returns Some if data sources return results for all requests received and None otherwise.

  31. final def orDie(implicit ev1: <:<[E, Throwable], ev2: CanFail[E]): ZQuery[R, Nothing, A]

    Permalink

    Converts this query to one that dies if a query failure occurs.

  32. final def orDieWith(f: (E) ⇒ Throwable)(implicit ev: CanFail[E]): ZQuery[R, Nothing, A]

    Permalink

    Converts this query to one that dies if a query failure occurs, using the specified function to map the error to a Throwable.

  33. final def provide(r: Described[R])(implicit ev: NeedsEnv[R]): ZQuery[Any, E, A]

    Permalink

    Provides this query with its required environment.

  34. final def provideCustomLayer[E1 >: E, R1 <: Has[_]](layer: Described[ZLayer[zio.ZEnv, E1, R1]])(implicit ev: <:<[zio.ZEnv with R1, R], tagged: zio.Tagged[R1]): ZQuery[zio.ZEnv, E1, A]

    Permalink

    Provides the part of the environment that is not part of the ZEnv, leaving a query that only depends on the ZEnv.

  35. final def provideLayer[E1 >: E, R0, R1 <: Has[_]](layer: Described[ZLayer[R0, E1, R1]])(implicit ev1: <:<[R1, R], ev2: NeedsEnv[R]): ZQuery[R0, E1, A]

    Permalink

    Provides a layer to this query, which translates it to another level.

  36. final def provideSome[R0](f: Described[(R0) ⇒ R])(implicit ev: NeedsEnv[R]): ZQuery[R0, E, A]

    Permalink

    Provides this query with part of its required environment.

  37. final def provideSomeLayer[R0 <: Has[_]]: ProvideSomeLayer[R0, R, E, A]

    Permalink

    Splits the environment into two parts, providing one part using the specified layer and leaving the remainder R0.

  38. final val run: ZIO[R, E, A]

    Permalink

    Returns an effect that models executing this query.

  39. final def runCache(cache: Cache): ZIO[R, E, A]

    Permalink

    Returns an effect that models executing this query with the specified cache.

    Returns an effect that models executing this query with the specified cache. This can be useful for deterministically "replaying" a query without executing any new requests.

  40. final def runLog: ZIO[R, E, (Cache, A)]

    Permalink

    Returns an effect that models executing this query, returning the query result along with the cache containing a complete log of all requests executed and their results.

    Returns an effect that models executing this query, returning the query result along with the cache containing a complete log of all requests executed and their results. This can be useful for logging or analysis of query execution.

  41. final def summarized[R1 <: R, E1 >: E, B, C](summary: ZIO[R1, E1, B])(f: (B, B) ⇒ C): ZQuery[R1, E1, (C, A)]

    Permalink

    Summarizes a query by computing some value before and after execution, and then combining the values to produce a summary, together with the result of execution.

  42. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  43. final def timed: ZQuery[R with Clock, E, (Duration, A)]

    Permalink

    Returns a new query that executes this one and times the execution.

  44. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  45. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  46. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  47. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  48. final def zip[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Permalink

    Returns a query that models the execution of this query and the specified query sequentially, combining their results into a tuple.

  49. final def zipLeft[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Permalink

    Returns a query that models the execution of this query and the specified query sequentially, returning the result of this query.

  50. final def zipPar[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Permalink

    Returns a query that models the execution of this query and the specified query in parallel, combining their results into a tuple.

  51. final def zipParLeft[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Permalink

    Returns a query that models the execution of this query and the specified query in parallel, returning the result of this query.

  52. final def zipParRight[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    Returns a query that models the execution of this query and the specified query in parallel, returning the result of the specified query.

  53. final def zipRight[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Permalink

    Returns a query that models the execution of this query and the specified query sequentially, returning the result of the specified query.

  54. final def zipWith[R1 <: R, E1 >: E, B, C](that: ZQuery[R1, E1, B])(f: (A, B) ⇒ C): ZQuery[R1, E1, C]

    Permalink

    Returns a query that models the execution of this query and the specified query sequentially, combining their results with the specified function.

  55. final def zipWithPar[R1 <: R, E1 >: E, B, C](that: ZQuery[R1, E1, B])(f: (A, B) ⇒ C): ZQuery[R1, E1, C]

    Permalink

    Returns a query that models the execution of this query and the specified query in parallel, combining their results with the specified function.

    Returns a query that models the execution of this query and the specified query in parallel, combining their results with the specified function. Requests composed with zipWithPar or combinators derived from it will be batched and deduplication and caching of requests will be applied.

Inherited from AnyRef

Inherited from Any

Ungrouped