EctoSavepoint (EctoSavepoint v0.1.0) View Source

Simple Ecto extension to use savepoints. Works with both postgrex and myxql.

Disclaimer: savepoints are not officially supported by Ecto for a reason. If you run into unexpected behaviour, please report so these cases can be documented here.

Add this line in your Repo:

use EctoSavepoint

And you can now do:

MyRepo.transaction(fn ->
  MyRepo.insert(...)

  MyRepo.savepoint("my_savepoint")

  MyRepo.insert(...)

  MyRepo.rollback_to_savepoint("my_savepoint")

  MyRepo.insert(...)
end)

This way, the insertions between savepoint and rollback are rolled back.

If you don't want to use, you can do the calls directly, as in:

EctoSavepoint.savepoint(MyRepo, "my_savepoint")

Link to this section Summary

Functions

Creates a savepoint

Creates a savepoint

Link to this section Functions

Link to this function

rollback_to_savepoint(repo, name)

View Source

Specs

rollback_to_savepoint(repo :: module(), name :: binary() | atom()) :: term()

Creates a savepoint

Should be called within the same transaction that created the savepoint

Specs

savepoint(repo :: module(), name :: binary() | atom()) :: term()

Creates a savepoint

Should be called within a transaction