msramos/ex_pipeline

Idea for how to implement ecto multi support

Closed this issue ยท 1 comments

Hi ๐Ÿ‘‹

I know this is just like a PoC or something. And it doesn't need to be this huge package or something. And its probably abandoned.

But, the only problem for me using this micro library, is that its not possible to wrap all steps inside a transaction.

Pipeline needs access to the Repo module, which can be done by an optional overridable function that by default returns nil.

If we use multi the state would be the changes in Ecto.Multi which change and evolve as you combine different multis together.

You can actually return a "pure" multi from a step by just

def get_company_step do
  # some other non multi code to get company
  Ecto.Multi.new()
  |> Ecto.Multi.put(:company, company)
end

or have the pipeline insert the returned value from the result returned by the step with the function name like:

# code to execute and combine steps
Ecto.Multi.new()
  |> Ecto.Multi.put(step_name, result)
# other code

I wonder how hard it is to fit this idea into this library ๐Ÿค”

nvm ๐Ÿ˜† just stupid of me .. i can of course just wrap the whole stuff in Repo.transaction and ensure that the pipeline fails if its an error :) ๐Ÿคฆ