rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.08k stars 161 forks source link

Command/Query Separation for ROM::Commands #606

Open Krule opened 6 years ago

Krule commented 6 years ago

According to CQS principle:

Every method should either be a command that performs an action, or a query that returns data to the caller, but not both.

With that in mind I would like to see a refactor of the following with at least an option for a commands not to perform additional database query in order to return the updated state (especially since we usually know what state is expected to be a result of the execution in advance):

abrthel commented 6 years ago

@solnic you were saying that you regret adding result: :many or result: :one but maybe a custom command set with result: :void could trigger this behavior?

solnic commented 6 years ago

@abrthel oh we definitely do not want to add another option for result :) I think all that's needed, is splitting methods in a way that we don't get results back in the same method. Once it's separated, we can conditionally get results using a separate method, and it could be configured.

abrthel commented 6 years ago

@solnic how would you envision configuring if results are returned or not?

I imagine, you'd want to be able to do something like: relation.command(:create, option_name: :value)

but what would you call the option?

solnic commented 6 years ago

So, been thinking about this and realized it's something we want to do in rom 5.0 / rom-sql 3.0.

paddor commented 4 years ago

@solnic Did something to fix this behavior make it into rom 5.0 / rom-sql 3.0? I'd like to avoid an additional SELECT query after a :create command.

solnic commented 4 years ago

@paddor no, but it's very likely it'll be addressed in rom 6.0.0 and rom-sql 4.0

solnic commented 4 years ago

I allowed myself to move this issue to the rom repository, because it's going to be a core feature and it will Just Work™ in rom-sql. This is now scheduled for 6.0.0 release.