GithubHelp home page GithubHelp logo

jomei / multibase Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 1.0 94 KB

Multiple databases support for Rails

Home Page: https://rubygems.org/gems/multibase-rails

License: MIT License

Ruby 87.37% JavaScript 1.23% CSS 1.40% HTML 10.00%
multibase-database rails database-management activerecord multibase

multibase's Introduction

Multibase Build Status Coverage Status Code Climate

Multiple database support for Rails.

This solution inspired by the SecondBase

Installation

Add this line to your application's Gemfile:

gem 'multibase-rails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multibase-rails

Usage

database.yml

Change config/database.yml so that settings for every database are placed under the following root key:

# config/database.yml
---
default: # default key for the default database
  test:
    adapter: sqlite3
    url:     ./base/test.sqlite3
  development:
    adapter: sqlite3
    url:     ./base/development.sqlite3
  production:
    adapter: postgresql
    url:     <%= ENV['DEFAULT_BASE_URL'] %>
custom_db: # the unique name for another database
  test:
    adapter: sqlite3
    url:     ./custom_db/test.sqlite3
  development:
    adapter: sqlite3
    url:     ./custom_db/development.sqlite3
  production:
    adapter: postgresql
    url:     <%= ENV['PERSONAL_BASE_URL'] %>

Configurations

You can define your own default database key in config/application.rb

config.multibase.default_key # Default: 'default'

Rake tasks

All db: rake tasks defined for each database as db:your_database_name:command, e.g. rake db:cusom_db:create

Rails Generators

Migrations

Use multibase:migration to generate migration for specific database

rails g multibase:migration <migration_name> <database_name> <options>

Example

rails g multibase:migration CreateMyTable custom_db foo:integer baz:string 

Rails models

All models should be inherit from Multibase::Base. Use using method to specify database connection Example

class Comment < Multibase::Base
  using :my_not_default_connection
end

License

The gem is available as open source under the terms of the MIT License.

multibase's People

Contributors

ahorner avatar jomei avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

ahorner

multibase's Issues

Copy of SecondBase not Properly Licensed

Thanks so much for posting your solution to the SecondBase issue (customink/secondbase#41) where a Third database option was requested. You appear to have copied SecondBase and re-published in a way that does not give credit to our MIT license and original authorship. For example:

https://github.com/customink/secondbase/blob/master/lib/second_base/databases.rake
https://github.com/jomei/multibase/blob/master/lib/multibase/tasks/database.rake

I am certain you did not intend to mis-credit our work. Would you mind correcting this and updating your LICENSE to include our original copyright as stated by the MIT? It would be nice too if you mentioned in your README where most of this code and inspiration came from. Thanks in advance!

cc @karledurante
cc @hmadison

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.