Created
January 31, 2012 02:32
-
-
Save rubypanther/1708342 to your computer and use it in GitHub Desktop.
Connecting to MS SQL with Ruby (platform independent)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
development: | |
adapter: sqlserver | |
mode: odbc | |
dsn: foo-bar-baz | |
username: ******** | |
password: ******** | |
encoding: utf8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'bundler/setup' | |
Bundler.require(:db) | |
env = 'development' | |
ActiveRecord::Base.establish_connection YAML.load_file( File.join(File.dirname(__FILE__),'..','config','database.yml'))[env] | |
$: << File.join(File.dirname(__FILE__),'..','app','models' ) | |
$: << File.join(File.dirname(__FILE__),'..','lib' ) | |
require 'my_model' | |
MyModel.where(:some_attr => 'omg')... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'http://rubygems.org' | |
group :db do | |
gem 'ruby-odbc', :require => 'odbc' | |
gem 'tiny_tds' | |
gem 'activerecord-sqlserver-adapter', '~> 3.1.0' | |
# gem 'composite_primary_keys', '~> 3.1.0' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel < ActiveRecord::Base | |
set_table_name 'my_legacy_table_name' | |
set_primary_key 'OmgIHateWidowsDBAs' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment