All Projects → feymartynov → ex_operation

feymartynov / ex_operation

Licence: other
A library for making domain operations in Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to ex operation

Etso
Ecto 3 adapter allowing use of Ecto schemas held in ETS tables
Stars: ✭ 226 (+584.85%)
Mutual labels:  ecto
absinthe error payload
Bridges the gap between Ecto and Absinthe for mutation payload
Stars: ✭ 102 (+209.09%)
Mutual labels:  ecto
kotlin-coroutines-jdbc
A library for interacting with blocking JDBC drivers using Kotlin Coroutines.
Stars: ✭ 40 (+21.21%)
Mutual labels:  transaction
mongodb-replica-set
Run MongoDB Atlas locally for testing
Stars: ✭ 42 (+27.27%)
Mutual labels:  transaction
WeCross
WeCross跨链路由
Stars: ✭ 183 (+454.55%)
Mutual labels:  transaction
prometheus-ecto
Prometheus.io collector for Elixir.Ecto
Stars: ✭ 74 (+124.24%)
Mutual labels:  ecto
Ex audit
Ecto auditing library that transparently tracks changes and can revert them.
Stars: ✭ 214 (+548.48%)
Mutual labels:  ecto
ActionLogic
A business logic abstraction gem that provides structure to the organization and composition of business logic (Ruby)
Stars: ✭ 29 (-12.12%)
Mutual labels:  business-logic
fat ecto
Query mechanism for Ecto
Stars: ✭ 20 (-39.39%)
Mutual labels:  ecto
query builder
Compose Ecto queries without effort
Stars: ✭ 56 (+69.7%)
Mutual labels:  ecto
AuthorizeCIM
Authorize.net CIM, AIM, and ARB Functions for Go Language
Stars: ✭ 36 (+9.09%)
Mutual labels:  transaction
datalogger
DataLogger foi projetado para ser uma biblioteca simples de log com suporte a vários providers.
Stars: ✭ 46 (+39.39%)
Mutual labels:  transaction
simpledbm
SimpleDBM is an Open Source Multi-Threaded Embeddable Transactional Database Engine in Java.
Stars: ✭ 51 (+54.55%)
Mutual labels:  transaction
Params
Easy parameters validation/casting with Ecto.Schema, akin to Rails' strong parameters.
Stars: ✭ 239 (+624.24%)
Mutual labels:  ecto
simple-mpesa
A simple example of how MPESA works. Works with all 3 types of customers i.e. Agents, Merchants and Subscribers. Allows you to configure a tariff and apply it to transactions. The project follows DDD principles.
Stars: ✭ 31 (-6.06%)
Mutual labels:  transaction
Ecto mnesia
Ecto adapter for Mnesia Erlang term database.
Stars: ✭ 223 (+575.76%)
Mutual labels:  ecto
ecto shorts
Shortcuts for ecto
Stars: ✭ 81 (+145.45%)
Mutual labels:  ecto
ember-pipeline
Railway oriented programming in Ember
Stars: ✭ 17 (-48.48%)
Mutual labels:  railway-oriented-programming
mysql-interview-questions
SQL Basics
Stars: ✭ 202 (+512.12%)
Mutual labels:  transaction
bitski-ios
Bitski iOS SDK
Stars: ✭ 18 (-45.45%)
Mutual labels:  transaction

ExOperation

Build Status

A library for making domain operations wrapped in a single database transaction.

Resources

Example

An operation definition:

defmodule MyApp.Book.Update do
  use ExOperation, params: %{
    id!: :integer,
    title!: :string,
    author_id: :integer
  }

  def validate_params(changeset) do
    changeset
    |> Ecto.Changeset.validate_length(:title, min: 5)
  end

  def call(operation) do
    operation
    |> find(:book, schema: MyApp.Book, preload: [:author])
    |> find(:author, schema: MyApp.Author, id_path: [:author_id], optional: true)
    |> step(:result, &do_update(operation.context, &1, operation.params))
    |> after_commit(&send_notifcation(&1))
  end

  defp do_update(context, txn, params) do
    txn.book
    |> Ecto.Changeset.cast(params, [:title])
    |> Ecto.Changeset.put_assoc(:author, txn.author)
    |> Ecto.Changeset.put_assoc(:updated_by, context.current_user)
    |> MyApp.Repo.update()
  end

  defp send_notification(txn) do
    # …
    {:ok, txn}
  end
end

The call:

context = %{current_user: current_user}

with {:ok, %{result: book}} <- MyApp.Book.Update |> ExOperation.run(context, params) do
  # …
end

Usage with Phoenix

An example Phoenix app can be found here: ex_operation_phoenix_example.

Features

  • Railway oriented domain logic pipeline.
  • Running all steps in a single database transaction. It uses Ecto.Multi inside.
  • Params casting & validation with Ecto.Changeset. Thanks to params library.
  • Convenient fetching of entitites from the database.
  • Context passing. Useful for passing current user, current locale etc.
  • Composable operations: one operation can call another through suboperation/3 function.
  • Changing operation scenario based on previous steps results with defer/2.
  • Hooks: before_transaction/1, after_commit/1.

Installation

Add the following to your mix.exs and then run mix deps.get:

def deps do
  [
    {:ex_operation, "~> 0.5.0"}
  ]
end

Add to your config/config.exs:

config :ex_operation,
  repo: MyApp.Repo

where MyApp.Repo is the name of your Ecto.Repo module.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].