View Source EdgeDB.Sandbox (EdgeDB v0.7.0)

Custom connection for tests that involve modifying the database through the driver.

This connection, when started, wraps the actual connection to EdgeDB into a transaction using the start transaction statement. And then further calls to EdgeDB.transaction/3 will result in executing declare savepoint statement instead of start transaction.

To use this module in tests, change the configuration of the :edgedb application in the config/test.exs:

config :edgedb,
  connection: EdgeDB.Sandbox

Then modify the test case to initialize the sandbox when you run the test and to clean the sandbox at the end of the test:

defmodule MyApp.TestCase do
  use ExUnit.CaseTemplate

  # other stuff for this case (e.g. Phoenix setup, Plug configuration, etc.)

  setup _context do
    EdgeDB.Sandbox.initialize(MyApp.EdgeDB)

    on_exit(fn ->
      EdgeDB.Sandbox.clean(MyApp.EdgeDB)
    end)

    :ok
  end
end

Summary

Functions

Release the connection transaction.

Wrap a connection in a transaction.

Functions

Link to this function

clean(client)

View Source (since 0.2.0)
@spec clean(GenServer.server()) :: :ok

Release the connection transaction.

Link to this function

initialize(client)

View Source (since 0.2.0)
@spec initialize(GenServer.server()) :: :ok

Wrap a connection in a transaction.