GithubHelp home page GithubHelp logo

livingsocial / connectomatic Goto Github PK

View Code? Open in Web Editor NEW

This project forked from relevance/connectomatic

3.0 63.0 1.0 110 KB

A simple gem that makes it easy to use multiple databases from Rails

License: MIT License

Ruby 100.00%

connectomatic's Introduction

connectomatic

This gem provides a simple way of managing multiple activerecord connections.

Supports Rails >= 3.2

Config structure

In addition to a rails project's primary database defined in config/database.yml, connectomatic allows you to define additional databases by placing any number of <database_name>.yml files in a config/databases/ directory. Each database config file uses the same format as a normal database.yml file.

Rake tasks

rake db:connectomatic:create_all creates all the defined databases. rake db:connectomatic:drop_all drops all the defined databases.

TODO: Schema dump and schema load for additional databases.

Using the databases

ActiveRecord Models

Just invoke the connectomatic method and pass it the name of the database you'd like it to use in your model object.

class MyModel < ActiveRecord::Base
      connectomatic(:my_database)
end

Migrations

To run a migration on an alternate database, just invoke the self.connectomatic method in your migration class and pass it the name of the database you'd like it to use.

class CreateSomething < ActiveRecord::Migration

      connectomatic(:my_database)

      def self.up
          #
      end

      def self.down
          #
      end
end

Explicitly specifying the default Rails database

Just pass :default to the connectomatic method in a Migration or a Model.

Credits

Inspiration for this gem (and several of the techniques used) were provided by Chris Herring's connection_ninja gem. (https://github.com/cherring/connection_ninja)

connectomatic's People

Contributors

bvandgrift avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.