Skuld.Effects.Port.Repo (skuld v0.23.0)

View Source

Effectful dispatch facade for Skuld.Effects.Port.Repo.Effectful.

Provides typed public functions returning computation(return_type) values that dispatch to the configured implementation via the Port effect. Also provides bang variants (unwrap or throw) and __key__ helpers for test stub matching.

Summary

Functions

Build a test stub key for the exists? port operation.

Build a test stub key for the get_by! port operation.

Build a test stub key for the aggregate port operation.

Calculate an aggregate over the given field.

Fetch all records matching a queryable.

Delete a record.

Port operation: delete!/1

Delete all records matching a queryable.

Check whether any record matching the queryable exists.

Fetch a single record by primary key. Returns nil if not found.

Fetch a single record by primary key, or dispatch Throw if not found.

Fetch a single record by the given clauses. Returns nil if not found.

Fetch a single record by the given clauses, or dispatch Throw if not found.

Insert a new record from a changeset.

Port operation: insert!/1

Insert all entries into a schema or source at once.

Fetch a single result from a query. Returns nil if no result.

Fetch a single result from a query, or dispatch Throw if no result.

Update an existing record from a changeset.

Port operation: update!/1

Update all records matching a queryable.

Functions

__key__(atom, changeset)

Build a test stub key for the exists? port operation.

__key__(atom, queryable, opts)

Build a test stub key for the get_by! port operation.

__key__(atom, source, entries, opts)

Build a test stub key for the aggregate port operation.

aggregate(queryable, aggregate, field)

Calculate an aggregate over the given field.

all(queryable)

Fetch all records matching a queryable.

delete(record)

@spec delete(struct()) ::
  Skuld.Comp.Types.computation({:ok, struct()} | {:error, Ecto.Changeset.t()})

Delete a record.

delete!(record)

@spec delete!(struct()) :: Skuld.Comp.Types.computation(struct())

Port operation: delete!/1

Like delete/1 but unwraps {:ok, value} or dispatches Throw on error.

delete_all(queryable, opts)

@spec delete_all(
  Ecto.Queryable.t(),
  keyword()
) :: Skuld.Comp.Types.computation({non_neg_integer(), nil | list()})

Delete all records matching a queryable.

exists?(queryable)

Check whether any record matching the queryable exists.

get(queryable, id)

Fetch a single record by primary key. Returns nil if not found.

get!(queryable, id)

Fetch a single record by primary key, or dispatch Throw if not found.

Mirrors Ecto.Repo.get!/2 — in the effectful context this dispatches Throw with {:not_found, queryable, id} instead of raising.

get_by(queryable, clauses)

@spec get_by(Ecto.Queryable.t(), keyword() | map()) ::
  Skuld.Comp.Types.computation(struct() | nil)

Fetch a single record by the given clauses. Returns nil if not found.

get_by!(queryable, clauses)

Fetch a single record by the given clauses, or dispatch Throw if not found.

Mirrors Ecto.Repo.get_by!/2.

insert(changeset)

@spec insert(Ecto.Changeset.t()) ::
  Skuld.Comp.Types.computation({:ok, struct()} | {:error, Ecto.Changeset.t()})

Insert a new record from a changeset.

insert!(changeset)

Port operation: insert!/1

Like insert/1 but unwraps {:ok, value} or dispatches Throw on error.

insert_all(source, entries, opts)

@spec insert_all(
  Ecto.Queryable.t() | binary(),
  [map() | keyword()],
  keyword()
) :: Skuld.Comp.Types.computation({non_neg_integer(), nil | list()})

Insert all entries into a schema or source at once.

one(queryable)

Fetch a single result from a query. Returns nil if no result.

one!(queryable)

Fetch a single result from a query, or dispatch Throw if no result.

Mirrors Ecto.Repo.one!/1.

update(changeset)

@spec update(Ecto.Changeset.t()) ::
  Skuld.Comp.Types.computation({:ok, struct()} | {:error, Ecto.Changeset.t()})

Update an existing record from a changeset.

update!(changeset)

Port operation: update!/1

Like update/1 but unwraps {:ok, value} or dispatches Throw on error.

update_all(queryable, updates, opts)

Update all records matching a queryable.