JackHQ

25 notes

Ruby Sequel Toolkit - MSSQL with (TinyTDS) - Connect to legacy databases

Connecting to MSSQL from ruby has always been painful

UnixOdbc, FreeTds, and TinyTds has really made the connections super easy.

Using the Ruby Sequel Toolkit, you are able to create an active model like interface to legacy databases which may not follow the active record standards.

class Store < Sequel::Model(:csstore)
  dataset.disable_insert_output!
  plugin :validation_helpers
  set_primary_key :store_id 
end

By specifying the real table name in the Sequel::Model declaration, you can call your class whatever you want.

dataset.disable_insert_output! - Is not necessary for every model, but if you have a table that is using triggers, you may want to add this line in your model. SQL 2008 returns and error when trying to call an insert or update statement with OUTPUT and no INTO.

set_primary_key - You can connect to any table, with any kind of primary key name, all you have to do is call the set_primary_key method with the name of the primary_key.

Recently a Ruby Sequel Rails 3 gem update was released, it should now be easier than ever to create a Rails 3 app and connect to a legacy MSSQL Database!

Filed under ruby mssql sequel toolkit

  1. jackhq posted this