View Source Dequel.Query.Context (Dequel v0.7.0)

Tracks joins and bindings during query building for relationship filtering.

When building queries with nested field paths like author.address.city, this module tracks which joins are needed and ensures joins are only created once per unique path.

Summary

Functions

Adds a preload path to the context

Ensures joins exist for a field path, returns {binding, updated_context}.

Creates a new empty context with optional schema for semantic analysis

Creates a new context with schema and prefix

Returns joins in dependency order (parent joins first)

Types

@type join_info() :: %{assoc: atom(), parent: atom(), binding: atom(), path: [atom()]}
@type t() :: %Dequel.Query.Context{
  joins: %{required([atom()]) => join_info()},
  prefix: String.t() | nil,
  preloads: [[atom()]],
  schema: module() | nil
}

Functions

@spec add_preload(t(), [atom()]) :: t()

Adds a preload path to the context

Link to this function

ensure_joins(ctx, field)

View Source
@spec ensure_joins(t(), atom() | [atom()]) :: {atom(), t()}

Ensures joins exist for a field path, returns {binding, updated_context}.

For simple fields (atoms) or single-segment paths, returns the base binding :q. For multi-segment paths, registers necessary joins and returns the binding for the deepest association.

@spec new(module() | nil) :: t()

Creates a new empty context with optional schema for semantic analysis

@spec new(module() | nil, String.t() | nil) :: t()

Creates a new context with schema and prefix

@spec ordered_joins(t()) :: [join_info()]

Returns joins in dependency order (parent joins first)