Dx is an Elixir library that allows adding inferred properties to Ecto schemas, defined by rules based on fields, associations or other inferred properties. You can then load/query them as if they were Ecto fields or associations using Dx's API.
It allows you to write declarative and easy-to-read domain logic by defining WHAT the rules are without having to care about HOW to execute them.
Under the hood, Dx's evaluation engine loads associations as needed concurrently in batches and can even translate your logic to Ecto queries directly.
Add dx
to your list of dependencies in mix.exs
:
def deps do
[
{:dx, github: "dx-beam/dx"}
]
end
When running Dx within transactions, please also add the following, until absinthe-graphql/dataloader#129 is closed:
def deps do
[
{:dataloader, github: "arnodirlam/dataloader", branch: "async-option", override: true}
]
end
Configure your repo in config.exs
:
config :dx, repo: MyApp.Repo
Import the formatter rules in .formatter.exs
:
[
import_deps: [:dx]
]
If you're new to Dx, the best place to start are the Guides.
Dx was started at Team Engine, where we've been developing it internally since January 2021. We've been using it in production since March 2021, and increasingly port our business logic to it. To make it an easy-to-adopt open-source library, the next steps are to:
- extract the code into this repo
- re-add tests (because they were domain-specific)
- write guides, a reference and an announcement
- resolve absinthe-graphql/dataloader#129 and re-add dataloader as a hex dependency
- find another name, because
infer
is already taken on hex.pm - release on hex.pm
This project is sponsored and kindly supported by Team Engine.
If you'd like to join us working on Dx and Refinery as a contractor, please reach out.