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

Make model repo configurable for read/write #4

Closed
paulcsmith opened this issue Apr 23, 2018 · 1 comment
Closed

Make model repo configurable for read/write #4

paulcsmith opened this issue Apr 23, 2018 · 1 comment

Comments

@paulcsmith
Copy link
Member

Sometimes people want to write a master and read from one or more replicated database for performance reasons.

Allowing people to override the repos for reads and writes would not be too hard and would make LuckyRecord more suitable for high performance/high availability requirements.

class MasterRepo < LuckyRecord::BaseRepo
end

class ReadRepoOne < LuckyRecord::BaseRepo
end

class ReadRepoTwo < LuckyRecord::BaseRepo
end

abstract class BaseModel
  def repo_for_reads
     # Choose one of the slave repos to read from
     [ReadRepoOne, ReadRepoTwo].sample
  end

  def repo_for_writes
    MasterRepo # Write to master
  end
end

MasterRepo.configure do
  settings.url = # connect to master
end
@paulcsmith paulcsmith transferred this issue from luckyframework/lucky_record Feb 2, 2019
@paulcsmith paulcsmith added this to the Avram next (stretch goals) milestone Jun 13, 2019
@paulcsmith
Copy link
Member Author

Closing favor of #138

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant