Dx.Scope (dx v0.3.5)

View Source

Used as intermediate data structure to translating defd code to SQL.

Summary

Types

t()

A scope struct used for translating defd code to SQL queries.

Functions

Explicitly create an unfiltered scope for a schema module.

Looks up a scope using the provided Dx.Evaluation struct. Runs any post-load processing defined in the scope.

Converts an atom to a scope using all/1 if given an atom, otherwise returns the input unchanged.

Looks up a scope if given {:ok, scope}, otherwise returns the input unchanged.

Looks up a scope if given one, otherwise wraps the input in an :ok tuple.

Types

t()

@type t() :: %Dx.Scope{
  aggregate?: boolean(),
  aggregate_default: term(),
  cardinality: :one | :many,
  main_condition_candidates: term(),
  opts: keyword(),
  plan: term(),
  post_load: {:loaded} | term(),
  ref: atom(),
  type: module()
}

A scope struct used for translating defd code to SQL queries.

Fields:

  • :plan - The query plan to be executed
  • :type - The schema module type
  • :cardinality - Either :one or :many (default: :many)
  • :aggregate? - Whether this scope represents an aggregate query
  • :aggregate_default - Default value to use for empty aggregates (e.g. 0 for count)
  • :ref - Root alias when building the Ecto query (default: :root)
  • :main_condition_candidates - Candidates for the main query condition
  • :post_load - Post-processing defd functions to apply after loading (default: {:loaded}),
               e.g. filters that could not be translated to SQL
  • :opts - Additional options (default: [])

Functions

add_conditions(scope, ext_ok_fun)

all(module)

Explicitly create an unfiltered scope for a schema module.

lookup(scope, eval)

Looks up a scope using the provided Dx.Evaluation struct. Runs any post-load processing defined in the scope.

map_plan(scope, fun)

maybe_atom(atom)

Converts an atom to a scope using all/1 if given an atom, otherwise returns the input unchanged.

maybe_load(other, eval)

Looks up a scope if given {:ok, scope}, otherwise returns the input unchanged.

maybe_lookup(scope, eval)

Looks up a scope if given one, otherwise wraps the input in an :ok tuple.