BoxTurtle.Schema.Change.API behaviour (BoxTurtle v0.1.0)

Copy Markdown View Source

Write operations generated by use BoxTurtle.Schema.Change: create, update and delete.

The counterpart to BoxTurtle.Schema.Query.API, with the idea that nothing outside a Query or Change module touches the Repo. Plain functions return {:ok, struct} / {:error, changeset} like Ecto.Repo; ! functions return the struct or raise.

Summary

Callbacks

Inserts a changeset, or a changeset built from a map (or struct) of attributes.

Deletes a struct, a changeset, or the row with the given primary key ({:error, :not_found} if absent).

Updates a changeset, or a struct with a map of changes.

Types

attrs()

@type attrs() :: map() | schema()

key()

@type key() :: term()

schema()

@type schema() :: Ecto.Schema.t()

Callbacks

create(arg1)

@callback create(attrs() | Ecto.Changeset.t()) ::
  {:ok, schema()} | {:error, Ecto.Changeset.t()}

Inserts a changeset, or a changeset built from a map (or struct) of attributes.

create!(arg1)

@callback create!(attrs() | Ecto.Changeset.t()) :: schema()

delete(arg1)

@callback delete(key() | schema() | Ecto.Changeset.t()) ::
  {:ok, schema()} | {:error, Ecto.Changeset.t() | :not_found}

Deletes a struct, a changeset, or the row with the given primary key ({:error, :not_found} if absent).

delete!(arg1)

@callback delete!(key() | schema() | Ecto.Changeset.t()) :: schema()

update(t)

@callback update(Ecto.Changeset.t()) :: {:ok, schema()} | {:error, Ecto.Changeset.t()}

Updates a changeset, or a struct with a map of changes.

update(schema, map)

@callback update(schema(), map()) :: {:ok, schema()} | {:error, Ecto.Changeset.t()}

update!(t)

@callback update!(Ecto.Changeset.t()) :: schema()

update!(schema, map)

@callback update!(schema(), map()) :: schema()