Code Monkey home page Code Monkey logo

Comments (8)

MatheusRich avatar MatheusRich commented on May 27, 2024 5

To me flow_in_a_db_transaction is too much verbose.

An alternative:

MyFlowWrappedInATransaction = Micro::Cases.flow(db_transaction: true, [
  CreateUser,
  CeateUserProfile
])

from u-case.

marcosgz avatar marcosgz commented on May 27, 2024 3

@serradura I totally agree with @mrbongiolo suggestion of :transaction naming: MyFlow = Micro::Cases.flow(transaction: MyCustomImplementation, [])

I've worked on applications that had more than one ActiveRecord or Sequel db connections. The transaction itself would not even need to be part of the project. And just provide mechanisms to group the a list of cases in a single transaction. And good examples in the documentation.

I don't think someone is using two ORM like this in same application. But a generic API would make that possible:

class SequelTransaction < Micro::Cases::Transaction
  def call!
    result = nil
    SequelDB.transaction do
      result = yield
      raise Sequel::Rollback if result.failure?
    end
    result
  end
end

class ActiveRecordTransaction < Micro::Cases::Transaction
  def call!
    result = nil
    ApplicationRecord.transaction do
      result = yield
      raise ActiveRecord::Rollback if result.failure?
    end
    result
  end
end

SignInFlow = Micro::Cases.flow(transaction: ActiveRecordTransaction, [CreateUser, CreateProfile])
SubscribeFlow = Micro::Cases.flow(transaction: SequelTransaction, [CreateOrder, CreateSubscription])

Ignore the syntax itself of this example. I'm talking the idea of a generic transaction.

from u-case.

mrbongiolo avatar mrbongiolo commented on May 27, 2024 2

@serradura how about?

MyFlow = Micro::Cases.flow(transaction: :db, [])
# or
MyFlow = Micro::Cases.flow(transaction: Micro::Cases::DB_TRANSACTION, [])
# or
MyFlow = Micro::Cases.flow(transaction: MyCustomImplementation, [])

from u-case.

marlosirapuan avatar marlosirapuan commented on May 27, 2024 1

why not just transaction? cause it's already a flow.. 🤔

from u-case.

mrbongiolo avatar mrbongiolo commented on May 27, 2024 1

from u-case.

serradura avatar serradura commented on May 27, 2024

@marlosirapuan I'm not sure about the method name yet. But this mode could be enabled using a kwarg. e.g:

Micro::Cases.flow(transaction: true, [
  CreateUser,
  CeateUserProfile
])

# --

class MyCase < Micro::Case
  flow(transaction: true, [
  CreateUser,
  CeateUserProfile
])

What do you think? cc: @MatheusRich

from u-case.

serradura avatar serradura commented on May 27, 2024

@MatheusRich I liked the usage of db_transaction kwarg. Much better and explicit!

from u-case.

serradura avatar serradura commented on May 27, 2024

@mrbongiolo I can think of different types of transactions. But I would like to start solving this first one: DB transactions. As you proposed, I believe that if a new kind of transaction appears, we could make db_transaction: true become an alias for transaction: :db. But its an excellent suggestion. Thank you!

from u-case.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.