Ecto.SoftDelete.Repo behaviour (ecto_soft_delete v2.0.3)
Adds soft delete functions to an repository.
defmodule Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
use Ecto.SoftDelete.Repo
end
Summary
Callbacks
Soft deletes a struct.
Updates the deleted_at
field with the current datetime in UTC.
It returns {:ok, struct}
if the struct has been successfully
soft deleted or {:error, changeset}
if there was a validation
or a known constraint error.
Same as soft_delete/1
but returns the struct or raises if the changeset is invalid.
Soft deletes all entries matching the given query.
Callbacks
soft_delete(struct_or_changeset)
@callback soft_delete(struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t()) :: {:ok, Ecto.Schema.t()} | {:error, Ecto.Changeset.t()}
Soft deletes a struct.
Updates the deleted_at
field with the current datetime in UTC.
It returns {:ok, struct}
if the struct has been successfully
soft deleted or {:error, changeset}
if there was a validation
or a known constraint error.
Examples
post = MyRepo.get!(Post, 42)
case MyRepo.soft_delete post do
{:ok, struct} -> # Soft deleted with success
{:error, changeset} -> # Something went wrong
end
soft_delete!(struct_or_changeset)
@callback soft_delete!(struct_or_changeset :: Ecto.Schema.t() | Ecto.Changeset.t()) :: Ecto.Schema.t()
Same as soft_delete/1
but returns the struct or raises if the changeset is invalid.
soft_delete_all(queryable)
@callback soft_delete_all(queryable :: Ecto.Queryable.t()) :: {integer(), nil | [term()]}
Soft deletes all entries matching the given query.
It returns a tuple containing the number of entries and any returned
result as second element. The second element is nil
by default
unless a select
is supplied in the update query.
Examples
MyRepo.soft_delete_all(Post)
from(p in Post, where: p.id < 10) |> MyRepo.soft_delete_all()