Comments (8)
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.
@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.
@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.
why not just transaction
? cause it's already a flow.. 🤔
from u-case.
from u-case.
@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.
@MatheusRich I liked the usage of db_transaction
kwarg. Much better and explicit!
from u-case.
@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)
- (BREAKING CHANGE) Allow a success result have access to its use case
- Create a configuration object to disable/enable the different gems features
- Rename branch master to main HOT 1
- Remove Micro::Case#call (Breaking Change)
- Normalize the name of all the private methods
- Add more methods to Micro::Case::Result quack like a Hash HOT 1
- Improve Micro::Case internal steps [NEW FEATURE]
- MyCase.call(hash) { |on| on.success {} } HOT 2
- [pt-BR] Aprimorar documentação HOT 1
- Adicionar documentação e exemplo sobre uso do Micro::Case #apply
- Add Micro::Case::Result#to_sym
- Micro::Case::Result#on - Enable pattern matching of result type and data for Ruby >= 2.2.0 HOT 1
- Allow calling a case inside of another one
- Add new Micro::Case::Config (enable_attributes_accept = true)
- Improve the inspect output
- Class/Case with an inner flow has a strange behavior when it receives an array of cases
- Micro::Case#transaction
- QUESTION: Navigating a flow HOT 2
- Micro::Case#then(:method_name) HOT 1
- DRAFT: Plans for the next major version (v5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from u-case.