EctoHooks behaviour (ecto_hooks v1.1.0) View Source
Module exposing various utility functions for interacting with, and introspecting the state of EctoHooks.
For more extensive usage instructions, please see associated documentation for
EctoHooks.Repo
.
Link to this section Summary
Functions
Alternative interface for initializing EctoHooks when use
-ed in a module as follows
Disables EctoHooks running for all future Repo operations in the current process.
Ensures EctoHooks run for all future Repo operations in the current process.
Returns a boolean indicating if any before_*
or after_*
hooks are allowed
to execute in the current process.
Utility function which returns the "nesting" of the current EctoHooks context.
Utility function which returns true if currently executing inside the context of an Ecto Hook.
Link to this section Functions
Alternative interface for initializing EctoHooks when use
-ed in a module as follows:
def MyApp.Repo do
use Ecto.Repo,
otp_app: :my_app,
adapter: Ecto.Adapters.Postgres
use EctoHooks
end
Please see EctoHooks.Repo
for more information about EctoHooks usage, examples,
and considerations.
Specs
disable_hooks(Keyword.t()) :: :ok
Disables EctoHooks running for all future Repo operations in the current process.
Internally, this is called with the options [global: false]
which gets
automatically cleared after triggering any Ecto.Repo
callback.
Specs
enable_hooks(Keyword.t()) :: :ok
Ensures EctoHooks run for all future Repo operations in the current process.
Internally, we use it to scope re-enabling hooks per execution, as we disabled
them as a mitigation for infinitely looping hooks caused by hooks triggering
other hooks. This happens when provided [global: false]
, which should only be
done internally.
Specs
hooks_enabled?() :: boolean()
Returns a boolean indicating if any before_*
or after_*
hooks are allowed
to execute in the current process.
Note that calls to Ecto.Repo
callbacks may reset or change the state of this flag,
and that this function is primarily exposed for introspection or debugging purposes.
Specs
hooks_ref_count() :: pos_integer()
Utility function which returns the "nesting" of the current EctoHooks context.
By default, every hook will "acquire" an EctoHook context and increment a ref count. These ref counts are automatically decremented once a hook finishes running.
This is provided as a lower level alternative the enable_hooks/1
, disable_hooks/1
,
and hooks_enabled?/0
functions.
Specs
in_hook?() :: boolean()
Utility function which returns true if currently executing inside the context of an Ecto Hook.
Link to this section Callbacks
Specs
after_delete(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
after_get(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
after_insert(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
after_update(schema_struct :: struct(), delta :: EctoHooks.Delta.t()) :: struct()
Specs
before_delete(queryable :: %Ecto.Queryable{}) :: %Ecto.Queryable{}
Specs
before_insert(queryable :: %Ecto.Queryable{}) :: %Ecto.Queryable{}
Specs
before_update(queryable :: %Ecto.Queryable{}) :: %Ecto.Queryable{}