Skip to content

Tools for using Postgres temporary tables with Ecto.

License

Notifications You must be signed in to change notification settings

synchronal/ecto_temp

Repository files navigation

EctoTemp

EctoTemp is an Ecto extension to support using PostgreSQL temporary tables with Ecto. This can be useful in situations where permanent tables may not be viable, such as when testing data migrations (where the schema at the time of test creation will differ over time), or to test modules that extend Ecto, but are not concernted with a specific schema.

This library is tested against the most recent 3 versions of Elixir and Erlang.

Installation

Add ecto_temp to mix.exs. Consider only adding it to the :test environment.

def deps do
  [
    {:ecto_temp, "~> 1.2", only: :test}
  ]
end

Usage

EctoTemp provides several macros which can be included by useing EctoTemp.

defmodule MyTest do
  use MyProject.DataCase
  use EctoTemp, repo: MyProject.Repo

  require EctoTemp.Factory
  alias EctoTemp.Factory

  deftemptable :things do
    column :data, :string, null: false
    column :data_with_default, :string, default: "default value"
    deftimestamps()
  end

  setup do
    create_temp_tables()
    :ok
  end

  test "insert records" do
    Factory.insert(:things, data: "stuff")
  end
end

Links

About

Tools for using Postgres temporary tables with Ecto.

Resources

License

Stars

Watchers

Forks

Packages

No packages published