calcinator v1.6.0 Calcinator.Resources.Ecto.Repo behaviour
Default callbacks for Calcinator.Resources
behaviour when backed by a single Ecto.Repo
Summary
Types
Name of a module that defines an Ecto.Schema.t
Functions
Allows access to Ecto.Adapters.SQL.Sandbox
Ecto.Changeset.t
using the default Ecto.Schema.t
for module
with params
- Casts
params
intodata
usingoptional_field/0
andrequired_fields/0
ofmodule
- Validates changeset with
module
ecto_schema_module/0
changeset/0
Deletes data
from module
’s repo/0
Uses query_options
as full associatons with no additions
Gets resource with id
from module
repo/0
- Insert
changeset
intomodule
repo/0
- Inserts
params
intomodule
repo/0
after converting them into anEcto.Changeset.t
Returns
Whether module
repo/0
is sandboxed and allow_sandbox_access/1
should be called
Updates struct
in module
repo/0
using changeset
Updates data
with params
in module
repo/0
Types
Functions
allow_sandbox_access(Resources.sandbox_access_token) :: :ok | {:already, :owner | :allowed} | :not_found
Allows access to Ecto.Adapters.SQL.Sandbox
Ecto.Changeset.t
using the default Ecto.Schema.t
for module
with params
- Casts
params
intodata
usingoptional_field/0
andrequired_fields/0
ofmodule
- Validates changeset with
module
ecto_schema_module/0
changeset/0
delete(module, Ecto.Schema.t) :: {:ok, Ecto.Schema.t} | {:error, :ownership} | {:error, Ecto.Changeset.t}
Deletes data
from module
’s repo/0
get(module, Resources.id, Resources.query_options) :: {:ok, Ecto.Schema.t} | {:error, :not_found} | {:error, :ownership}
Gets resource with id
from module
repo/0
.
Returns
{:error, :not_found}
- ifid
is not found inmodule
’srepo/0
.{:error, :ownership}
- ifDBConnection.OwnershipError
due to connection sharing error during tests.{:ok, struct}
- ifid
is found inmodule
’srepo/0
. Associations will also be preloaded instruct
based onResources.query_options
.
insert(module, Ecto.Changeset.t | map, Resources.query_options) :: {:ok, Ecto.Schema.t} | {:error, :ownership} | {:error, Ecto.Changeset.t}
- Insert
changeset
intomodule
repo/0
- Inserts
params
intomodule
repo/0
after converting them into anEcto.Changeset.t
Returns
{:error, :ownership}
- connection to backing store was not owned by the calling process{:error, Ecto.Changeset.t}
- ifchangeset
cannot be inserted intomodule
repo/0
{:ok, struct}
- ifchangeset
was inserted in tomodule
repo/0
.struct
is preloaded with associations according toResource.query_iptions
inopts
.
list(module, Resources.query_options) :: {:ok, [Ecto.Schema.t], nil} | {:error, :ownership}
Returns
{:error, :ownership}
- connection to backing store was not owned by the calling process{:ok, [struct], nil}
-[struct]
is the list of allmodule
ecto_schema_module/0
inmodule
repo/0
. There is no (current) support for pagination: pagination is thenil
in the 3rd element of the tuple.
Whether module
repo/0
is sandboxed and allow_sandbox_access/1
should be called.
update(module, Ecto.Changeset.t, Resources.query_options) :: {:ok, Ecto.Schema.t} | {:error, :ownership} | {:error, Ecto.Changeset.t}
Updates struct
in module
repo/0
using changeset
.
Returns
{:error, :ownership}
- connection to backing store was not owned by the calling process{:error, Ecto.Changeset.t}
- if thechangeset
had validations error or it could not be used to updatestruct
inmodule
repo/0
.{:ok, struct}
- the updatedstruct
. Associations are preloaded usingResources.query_options
inquery_options
.
update(module, Ecto.Schema.t, Resources.params, Resources.query_options) :: {:ok, Ecto.Schema.t} | {:error, Ecto.Changeset.t}
Updates data
with params
in module
repo/0
Returns
{:error, :ownership}
- connection to backing store was not owned by the calling process{:error, Ecto.Changeset.t}
- if the changeset derived from updatingdata
withparams
had validations error or it could not be used to updatedata
inmodule
repo/0
.{:ok, struct}
- the updatedstruct
. Associations are preloaded usingResources.query_options
inquery_options
.
Callbacks
The Ecto.Schema
module stored in repo/0
.
The full list of associations to preload in
Calcinator.Resources.get/2
Calcinator.Resources.insert/2
Calcinator.Resources.list/1
Calcinator.Resources.update/2
Calcinator.Resources.update/3
Should combine the request-specific associations in Resources.query_options
with any default associations and/or
transform requested associations to repo/0
-specific associations.
The Ecto.Repo
that stores ecto_schema_module/0
.