Giter Site home page Giter Site logo

db2_odbc_adapter's Introduction

DB2 ODBCAdapter

Gem Version

An ActiveRecord DB2 ODBC adapter. It is a fork of ActiveRecord odbc_adapter with a minor hack so that it can work only with DB2 Connection on Rails 6+.

Installation

Ensure you have the ODBC driver installed on your machine. And have a DB2 server to connect.

Add this line to your application's Gemfile:

gem 'db2_odbc_adapter'

And then execute:

  $ bundle

Or install it yourself as:

  $ gem install db2_odbc_adapter

Usage

Configure your database.yml by using the dsn to point to a DSN that corresponds to a valid entry in your ~/etc/odbc.ini file. Since Rails 6+ support multiple database, so the database configuration is as follow:

# config/database.yml

default: &default
.
.
.
db2_connection: &db2_connection   // as you wish
  adapter: odbc                   // compulsory 
  dsn: YourDatabaseDSN            // as in the odbc.ini file

development:
  primary:
    .
    .
    .
  db2:
    <<: *db2_connection

test:
  primary:
    .
    .
    .
  db2:
    <<: *db2_connection

production:
  primary:
    .
    .
    .
  db2:
    <<: *db2_connection

and use it at your model as follow.

Single table connection

  class MyTable < ActiveRecord::Base
    establish_connection :db2
    self.table_name  = "TableName"       #table name at DB2 server
    self.primary_key = 'column_name'    #colum that have unique content since db2 have RRN instead of id 
  end

Raw SQL connection

  class MyCustomModel < ActiveRecord::Base
    establish_connection :db2
    scope :scope_name, -> arg {
      connection.exec_query("SELECT * FROM .........WHERE ..'#{arg}...")
    }
  end

ActiveRecord models that use this connection will now be connecting to the configured database using the ODBC driver.

License

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

db2_odbc_adapter's People

Contributors

kddnewton avatar lumentut avatar prurph avatar bwarminski avatar mshearer76 avatar

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.