Skuld.Query (skuld v0.27.2)

View Source

Primary API for query contracts, wiring, and caching.

Defining a query contract

defmodule MyApp.Queries do
  use Skuld.Query

  deffetch get_user(id :: String.t()) :: User.t() | nil
  deffetch get_orders(user_id :: String.t()) :: [Order.t()]
end

Wiring executors

comp
|> Skuld.Query.with_executor(MyApp.Queries, MyApp.Queries.EctoExecutor)
|> FiberPool.with_handler()
|> Comp.run()

With caching

comp
|> Skuld.Query.with_cached_executor(MyApp.Queries, MyApp.Queries.EctoExecutor)
|> FiberPool.with_handler()
|> Comp.run()

Summary

Functions

Install a caching-wrapped executor for a single contract. Shorthand for with_cached_executors/2.

Install caching-wrapped executors for multiple contracts. Initialises a scoped cache and wraps executors so identical queries return cached results without re-executing.

Install an executor module for a single query contract.

Install executor modules for multiple query contracts. Accepts either a list of {contract_module, executor_module} tuples or a map.

Functions

with_cached_executor(comp, contract_module, executor_module)

Install a caching-wrapped executor for a single contract. Shorthand for with_cached_executors/2.

with_cached_executors(comp, pairs)

Install caching-wrapped executors for multiple contracts. Initialises a scoped cache and wraps executors so identical queries return cached results without re-executing.

with_executor(comp, contract_module, executor_module)

Install an executor module for a single query contract.

The executor module must implement the contract's callbacks.

with_executors(comp, pairs)

Install executor modules for multiple query contracts. Accepts either a list of {contract_module, executor_module} tuples or a map.