Read operations generated by use BoxTurtle.Schema.Query.
Functions come in pairs: the plain form returns {:ok, result} / {:error, reason}, the ! form returns the
result directly (nil when get!/2 finds nothing).
Call-time options
:filters- keyword list of filters, seeBoxTurtle.Schema.Filters:sort- sort specification, seeBoxTurtle.Schema.Sort:page- page number or[number: n, size: s], seeBoxTurtle.Schema.Pagination:preloads- associations to preload, nested to any depth ([:author, comments: :user]). They areLEFT JOINed and loaded in the same query, seeBoxTurtle.Schema.Query.Helpers.preloads/3. Ignored by aggregates:distinct- columns forDISTINCT ON(PostgreSQL only); a count uses the first one asCOUNT(DISTINCT column), which works on every database:group_by- columns to group by;countthen returns a list of maps:aggregate-:count(used internally bycount/1):ignore_defaults- when true, the module's default sort, preloads and distinct are not applied:query_opts- options passed toEcto.Repo.all/2bylist/1
Any use-time setting (:repo, :schema, :default_sort, ...) can also be overridden per call; see
BoxTurtle.Schema.Query.Options.API.
Extension functions
The *_by callbacks are optional. They are generated with BoxTurtle.Schema.Query.extend/2 and
BoxTurtle.Schema.Query.delegate/1, which scope a query by a pattern (e.g. "all posts of this %Author{}").
Summary
Callbacks
Counts rows, or rows per group when :group_by is given.
Counts rows scoped by a pattern. A nil pattern counts everything.
Fetches a row by primary key (or by a map of key columns). {:error, :not_found} when absent.
Fetches the row identified by a pattern.
Lists rows.
Lists rows scoped by a pattern. A nil pattern lists everything.
Applies the options (sort, filters, paging, preloads or aggregation) to an existing queryable.
Builds a query on the schema from the options, without running it.
Builds a query scoped by a pattern.
Types
@type opts() :: keyword()
@type schema() :: Ecto.Schema.t()
Callbacks
Counts rows, or rows per group when :group_by is given.
Counts rows scoped by a pattern. A nil pattern counts everything.
Fetches a row by primary key (or by a map of key columns). {:error, :not_found} when absent.
Fetches the row identified by a pattern.
@callback list() :: {:ok, [schema()]}
Lists rows.
@callback list!() :: [schema()]
Lists rows scoped by a pattern. A nil pattern lists everything.
@callback pipe_query!(Ecto.Queryable.t()) :: Ecto.Queryable.t()
Applies the options (sort, filters, paging, preloads or aggregation) to an existing queryable.
@callback pipe_query!(Ecto.Queryable.t(), opts()) :: Ecto.Queryable.t()
@callback query!() :: Ecto.Queryable.t()
Builds a query on the schema from the options, without running it.
@callback query!(opts()) :: Ecto.Queryable.t()
@callback query_by!(pattern :: term()) :: Ecto.Queryable.t()
Builds a query scoped by a pattern.
@callback query_by!(pattern :: term(), opts()) :: Ecto.Queryable.t()