BlogEngine.Storage (blog_engine v0.1.0)

Copy Markdown View Source

Prefix-safe access to the host application's Ecto Repo.

Summary

Types

The result transaction/2 returns for an Ecto.Multi.

Functions

Runs a prefix-normalized all query through the context Repo.

Deletes a prefixed copy of a schema through the context Repo.

Inserts a prefixed copy of a changeset through the context Repo.

Runs a prefix-normalized one query through the context Repo.

Preloads associations using the context prefix.

Returns a copy of a schema or changeset with context-prefixed metadata.

Applies the context prefix to a prefix-neutral queryable.

Runs an Ecto Multi or zero-arity callback in a Repo transaction.

Reduces an Ecto.Multi transaction result to a two-tuple.

Updates a prefixed copy of a changeset through the context Repo.

Types

multi_result()

@type multi_result() :: {:ok, map()} | {:error, term(), term(), map()}

The result transaction/2 returns for an Ecto.Multi.

Functions

all(context, queryable)

@spec all(BlogEngine.Context.t(), term()) :: [term()]

Runs a prefix-normalized all query through the context Repo.

delete(context, schema, opts \\ [])

@spec delete(BlogEngine.Context.t(), Ecto.Schema.t(), keyword()) ::
  {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}

Deletes a prefixed copy of a schema through the context Repo.

insert(context, changeset, opts \\ [])

@spec insert(BlogEngine.Context.t(), Ecto.Changeset.t(), keyword()) ::
  {:ok, term()} | {:error, Ecto.Changeset.t()}

Inserts a prefixed copy of a changeset through the context Repo.

one(context, queryable)

@spec one(BlogEngine.Context.t(), term()) :: term() | nil

Runs a prefix-normalized one query through the context Repo.

preload(context, data, preloads)

@spec preload(BlogEngine.Context.t(), term(), term()) :: term()

Preloads associations using the context prefix.

put_prefix(context, changeset)

Returns a copy of a schema or changeset with context-prefixed metadata.

query(context, queryable)

@spec query(BlogEngine.Context.t(), term()) :: Ecto.Query.t()

Applies the context prefix to a prefix-neutral queryable.

transaction(context, multi)

@spec transaction(BlogEngine.Context.t(), Ecto.Multi.t() | (-> term())) ::
  {:ok, term()} | {:error, term()} | {:error, term(), term(), map()}

Runs an Ecto Multi or zero-arity callback in a Repo transaction.

Inspectable changeset and query operations in a Multi must already resolve to the context prefix. Nested subqueries, CTEs, and combinations fail closed until recursive validation is supported. Opaque run and dynamic operations are a trusted internal boundary because Ecto.Multi.to_list/1 does not expose the values they will build at runtime.

unwrap(arg, on_success)

@spec unwrap(multi_result(), (map() -> success)) :: success | {:error, term()}
when success: var

Reduces an Ecto.Multi transaction result to a two-tuple.

on_success receives the committed changes map and returns the caller's own success value. A failed operation always becomes {:error, reason} carrying the reason of the operation that failed, so callers never repeat the four-element shape transaction/2 returns for a Multi.

update(context, changeset, opts \\ [])

@spec update(BlogEngine.Context.t(), Ecto.Changeset.t(), keyword()) ::
  {:ok, term()} | {:error, Ecto.Changeset.t()}

Updates a prefixed copy of a changeset through the context Repo.