github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

mauricio / master_slave_adapter

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 96
    • 4
  • Source
  • Commits
  • Network (4)
  • Issues (1)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

An ActiveRecord database adapter that allows you to setup a "master/slave" environment — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Apply fixes suggested by http://github.com/deepak-srishti 
mauricio (author)
Sun Nov 08 17:59:56 -0800 2009
commit  67fd679dd5cfc3ba2c49a2fff01505f1783275ad
tree    5dc9d5fec6be56e9ed5b1a5952c85130d089b590
parent  bf09ca61be942a26b7c29a1838443ff12ace475d
master_slave_adapter /
name age
history
message
file .gitignore Sun Aug 23 11:23:10 -0700 2009 More specs, connection test can now be disabled... [mauricio]
file LICENSE Fri Jun 12 08:05:53 -0700 2009 Initial commit [mauricio]
file README Sun Nov 08 17:59:56 -0800 2009 Apply fixes suggested by http://github.com/deep... [mauricio]
file init.rb Fri Jun 12 08:05:53 -0700 2009 Initial commit [mauricio]
directory lib/ Sun Nov 08 17:59:56 -0800 2009 Apply fixes suggested by http://github.com/deep... [mauricio]
directory specs/ Sun Aug 23 11:23:10 -0700 2009 More specs, connection test can now be disabled... [mauricio]
README
master_slave_adapter - maurĂ­cio DOT linhares AT gmail DOT com
====

This simple plugin acts as a common ActiveRecord adapter and allows you to
setup a master-slave environment using any database you like (and is supported
by ActiveRecord).

This plugin works by handling two connections, one to a master database,
that will receive all non-"SELECT" statements, and another to a slave database
that that is going to receive all SELECT statements. It also tries to do as
little black magic as possible, it works just like any other ActiveRecord database
adapter and performs no monkeypatching at all, so it's easy and simple to use
and understand.

The master database connection will also receive SELECT calls if a transaction
is active at the moment or if a command is executed inside a "with_master" block:

ActiveRecord::Base.with_master do # :with_master instructs the adapter
    @users = User.all             # to use the master connection inside the block
end

To use this adapter you just have to install the plugin:

ruby script/plugin install git://github.com/mauricio/master_slave_adapter.git

And then configure it at your database.yml file:

development:
  database: sample_development
  username: root
  adapter: master_slave             # the adapter must be set to "master_slave"
  host: 10.21.34.80
  master_slave_adapter: mysql       # here's where you'll place the real database adapter name
  disable_connection_test: true     # this will disable the connection test before use,
                                    # can possibly improve the performance but you could also
                                    # hit stale connections, default is false
  eager_load_connections: true      # connections are lazy loaded by default, you can load gem eagerly setting this to 
  true
  master:                           # and here's where you'll add the master database configuration
    database: talkies_development   # you shouldn't specify an "adapter" here, the
    username: root                  # value at "master_slave_adapter" is going to be used
    host: 10.21.34.82
    adapter: postgresql             # you can use another adapter for the master connection if needed
                                    # if you don't set it the "master_slave_adapter" property will be used
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server