Bonfire.Ecto
contains Ecto
transactional support as acts for Bonfire.Epics
Bonfire.Ecto
is designed to facilitate complex Ecto transaction handling within an Elixir application that uses Bonfire.Epics
to execute a sequence of operations (or Acts
). These modules provide a structured way to manage database transactions as a series of acts and managing them within an Epic
, offering flexibility and control over database interactions, ensuring that transactions are executed efficiently.
-
Bonfire.Ecto.Acts.Begin
- Responsible for initiating a transaction if certain conditions are met. It ensures that the transaction is only started when it is sensible to do so, based on the current state of the
Epic
.
- Responsible for initiating a transaction if certain conditions are met. It ensures that the transaction is only started when it is sensible to do so, based on the current state of the
-
Bonfire.Ecto.Acts.Work
- Handles queued database operations within a transaction. Operations are queued using the
Bonfire.Ecto.Acts.Work.add/2
function and executed if there are no errors in theEpic
or changesets.
- Handles queued database operations within a transaction. Operations are queued using the
-
Bonfire.Ecto.Acts.Commit
- A placeholder marker used by
Bonfire.Ecto.Acts.Begin
to identify when to commit the transaction.
- A placeholder marker used by
Ensure that you have Ecto
and Bonfire.Epics
installed and configured in your application, and then install this linrary.
Refer to Bonfire.Epics
docs to define some Act
s and Epic
s: https://github.com/bonfire-networks/bonfire_epics
Queue operations by calling the Bonfire.Ecto.Acts.Work.add/2
function, providing the epic and a key representing the changeset to be processed.
epic = Bonfire.Ecto.Acts.Work.add(epic, :some_changeset)
# First come the Acts that prepare the changeset and call `Bonfire.Ecto.Acts.Work.add/2` to queue it
# Open a Postgres transaction and actually do the insertions in DB
Bonfire.Ecto.Acts.Begin,
# Run our inserts
Bonfire.Ecto.Acts.Work,
Bonfire.Ecto.Acts.Commit,
# Then can come some Acts that process the result of the transaction