Supra (Supra v3.0.1)
Documentation for Supra.
Summary
Functions
Returns the number of rows in queryable
Limits queryable to one result and returns that result
Returns query as a string with all parameters formatted in the specified style. Styles are rendered via
IO.ANSI which will only render stylized text if it thinks the output device can show them.
Applies limit to queryable
Streams an Ecto query without requiring a transaction.
Streams an Ecto query without requiring a transaction. Must be given the name of a non-nullable field to iterate over in batches.
Types
@type change(type) :: Ecto.Changeset.t(type)
@type preloadable() :: [Ecto.Schema.t()] | Ecto.Schema.t() | nil
@type preloadable(type) :: [type] | type | nil
@type result(type) :: {:ok, type} | {:error, Ecto.Changeset.t(type)}
@type result(ok_t, error_t) :: {:ok, ok_t} | {:error, Ecto.Changeset.t(error_t)}
@type stream_by_opt() :: {:repo, module()} | {:batch_size, pos_integer()} | {:order, :asc | :desc} | {:preload, term()}
@type stream_by_opts() :: [stream_by_opt()]
@type stream_opts() :: [stream_opt()]
Functions
@spec count(Ecto.Queryable.t(), [{:repo, Ecto.Repo.t()}]) :: non_neg_integer()
Returns the number of rows in queryable
@spec first(Ecto.Queryable.t(), [{:repo, Ecto.Repo.t()}]) :: Ecto.Schema.t() | nil
Limits queryable to one result and returns that result
@spec format(Ecto.Queryable.t(), Supra.Format.style(), [{:repo, Ecto.Repo.t()}]) :: binary()
Returns query as a string with all parameters formatted in the specified style. Styles are rendered via
IO.ANSI which will only render stylized text if it thinks the output device can show them.
:brightrenders parameters in brighter text, which is the most subtle of all the supported styles and may be hard to differentiate.:colorrenders parameters in different colors depending on their data types viaIO.ANSI.syntax_colors/0.:inverse(the default) renders parameters with an inverse background. This is quite visible and also compatible when some other code such as a logger is colorizing the query.:underlineis a bit more subtle than:inversebut more visible than:bright.
@spec limit(Ecto.Queryable.t(), non_neg_integer()) :: Ecto.Queryable.t()
Applies limit to queryable
@spec stream(Ecto.Query.t(), stream_opts()) :: Enum.t()
Streams an Ecto query without requiring a transaction.
Options
cursor_fun :: fun()required - An arity-1 function that will be given the last value returned from the stream. This function will be evaluated to save the cursor value that will be used to find the next batch.next_batch_fun :: fun()required - An arity-1 function that will be given the cursor saved from the previous batch. This function must return anEcto.Query.dynamic_expr/0that may used in a where clause to find the next batch.repo :: module()required - AnEcto.Repoexecute queries.batch_size :: integer() deault100- The size of batches to query from the database. -preload :: term()optional - An optional set of preloads to apply to each batch before emitting members to the stream. This is preferred over query-time preloads, as described below. ## Warning When streaming a query with query-time preloads, associations may be truncated for the last record of each stream batch. The:preloadoption toSupra.stream/2andSupra.stream_by/3` operates on the returned values of each batch, and thus does not exhibit this problem.
@spec stream_by(Ecto.Query.t(), atom(), stream_by_opts()) :: Enum.t()
Streams an Ecto query without requiring a transaction. Must be given the name of a non-nullable field to iterate over in batches.
Options
repo :: module()required - AnEcto.Repoexecute queries.batch_size :: integer() deault100- The size of batches to query from the database. -order :: :asc | :descdefault:asc- The order in which to iterate over batches. -preload :: term()optional - An optional set of preloads to apply to each batch before emitting members to the stream. This is preferred over query-time preloads, as described below. ## Warning When streaming a query with query-time preloads, associations may be truncated for the last record of each stream batch. The:preloadoption toSupra.stream/2andSupra.stream_by/3` operates on the returned values of each batch, and thus does not exhibit this problem.