Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement command/query separation for Repository, by introducing #fetch #207

Merged
merged 3 commits into from Sep 10, 2015

Conversation

@jodosha
Copy link
Member

jodosha commented Jul 10, 2015

Repository.execute

This PR introduces a breaking change: Repository.execute will return nil.

This method is still useful if we want to send commands against a database, without expecting any returning value.

class ArticleRepository
  include Lotus::Repository

  def self.reset_comment_count
    execute "UPDATE articles SET comments_count = 0"
  end
end

Repository.fetch

In order to retrieve raw records from the database, we have introduced .fetch.
It will return a collection of hashes, representing the RAW records as they are returned from the database, WITHOUT involving coercions and mapper.

Given the following mapping:

collection :articles do
  # ...
  attribute :id, Integer, as: :s_id
  attribute :title, Integer, as: s_title
end

It will return

class ArticleRepository
  include Lotus::Repository

  def self.find_raw
    fetch "SELECT * FROM articles"
  end
end


ArticleRepository.find_raw
  # => [{:s_id=>"1", :s_title=>"Art 1"}] # They are not coerced or mapped

Ref #191

/cc @lotus/core-team

@jodosha jodosha self-assigned this Jul 10, 2015
@jodosha jodosha added this to the v0.5.0 milestone Jul 10, 2015
@jodosha

This comment has been minimized.

Copy link
Member Author

jodosha commented Jul 10, 2015

@darwinrc

This comment has been minimized.

Copy link

darwinrc commented Jul 10, 2015

Nice thought taking into account CQRS, @jodosha. Congrats!

I guess it means I must change my execute calls.

@AlfonsoUceda AlfonsoUceda mentioned this pull request Aug 12, 2015
7 of 7 tasks complete
jodosha added a commit that referenced this pull request Sep 10, 2015
Implement command/query separation for Repository, by introducing #fetch
@jodosha jodosha merged commit 3ab57ee into master Sep 10, 2015
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details
@jodosha jodosha deleted the repository-fetch branch Sep 10, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.