dawdle_db v0.5.0 DawdleDB.Handler behaviour
Defines a handler for database events on a single table.
To define an event handler, use DawdleDB.Handler
and provide a Ecto schema
type that you wish to handle. Then, override the callbacks
handle_insert/1
, handle_update/2
, handle_delete/1
,
as appropriate.
Examples
defmodule MyApp.TestDBHandler do
use DawdleDB.Handler, type: [MyApp.MySchema]
alias MyApp.MySchema
def handle_insert(%MySchema{} = new) do
# Do something...
end
def handle_update(%MySchema{} = new, old) do
# Do something else...
end
def handle_delete(%MySchema{} = old) do
# Default case
end
end
Link to this section Summary
Callbacks
This function is called when DawdleDB pulls a delete event for the specified table from the queue. The function is executed for its side effects and the return value is ignored.
This function is called when DawdleDB pulls an insert event for the specified table from the queue. The function is executed for its side effects and the return value is ignored.
This function is called when DawdleDB pulls an update event for the specified table from the queue. The function is executed for its side effects and the return value is ignored.
Link to this section Callbacks
handle_delete(old)
handle_delete(old :: Ecto.Schema.t()) :: any()
handle_delete(old :: Ecto.Schema.t()) :: any()
This function is called when DawdleDB pulls a delete event for the specified table from the queue. The function is executed for its side effects and the return value is ignored.
handle_insert(new)
handle_insert(new :: Ecto.Schema.t()) :: any()
handle_insert(new :: Ecto.Schema.t()) :: any()
This function is called when DawdleDB pulls an insert event for the specified table from the queue. The function is executed for its side effects and the return value is ignored.
handle_update(new, old)
handle_update(new :: Ecto.Schema.t(), old :: Ecto.Schema.t()) :: any()
handle_update(new :: Ecto.Schema.t(), old :: Ecto.Schema.t()) :: any()
This function is called when DawdleDB pulls an update event for the specified table from the queue. The function is executed for its side effects and the return value is ignored.