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

Provide Example for use outside of Rails #9

Open
falsetto opened this issue Dec 6, 2011 · 0 comments
Open

Provide Example for use outside of Rails #9

falsetto opened this issue Dec 6, 2011 · 0 comments

Comments

@falsetto
Copy link

falsetto commented Dec 6, 2011

Is it possible to use read_from_slave in a standalone environment? I'm trying the following without success (all reads, even inside of with_primary_slave go to the master). I'm using activerecord 3.1.3 and read_from_slave 0.5.2.

config/database.yml

adapter: mysql
database: master
username: asdf
password: asdf
host: xxx.xxx.xxx.xxx
port: 3306
slaves:
  primary_slave:  slave_for_reads

slave_for_reads:
  adapter: mysql
  database: slave
  username: asdf
  password: asdf
  host: xxx.xxx.xxx.xxx
  port: 3306

example code

require 'rubygems'
require 'active_record'

db_config = YAML::load(File.open(File.join(File.dirname(__FILE__),'config','database.yml')))
ActiveRecord::Base.establish_connection(db_config)
require 'read_from_slave'

class Member < ActiveRecord::Base; end

# Queries master instead of slave
Member.first
# Also queries master instead of slave
ActiveRecord::Base.with_primary_slave do
  Member.first
end
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