After 4 weeks of work, the ActiveRecord SQL Server adapter is now ready for Rails v4.2.0 and in pre-release status. The list of features is impressive. But first, some bad news. Code named Kantishna, after a small community in Denali area of Alaska, the adapter is only for SQL Server 2012 and higher. This is a good thing because these versions of SQL Server have something we have needed for a very long time, simple offset and limit windowing functions.
FETCH Can Happen
Sure there are hacks like
ROW_NUMBER and in theory these work. In reality it has caused our code to be incredibly complex and infected all parts of the adapter. Problems were often solved by using regular expressions and affected performance. Even worse, I think it kept people from contributing to the project. Worry not, if you are on an older version of SQL Server, please feel free to use an older version of Rails and the adapter.
For the rest, FETCH can happen and that is indeed what we are using,
FETCH. Here is a great article that describes its basic usage. To see the benefits, take a quick look at our latest Arel visitor and note the difference.
For full details check out the latest CHANGELOG on our project repo. But here is a great summary. The v4.2.0 adapter is the strongest version to date!
TYPE CASTING: A few weeks ago I wrote a full article on the new Type objects in ActiveRecord 4.2. These objects help us do a much better job of ensuring data going in and out of the DB are proper. They will play a huge role in Rails 5.0 when the API becomes public. In Rails 4.2 they help us quote values and output proper schema.rb files. We have aliased our type namespace to
ActiveRecord::Type::SQLServer and these objects will help us win at every datatype FreeTDS supports.
OBJECT IDENTIFICATION: Inspired by the PostgreSQL adapter, we now have a plain ruby object which is responsible for identifying servers, databases, objects, and schemas. No more ad-hoc quoting which caused us to blow up when needing to use quoted/unquoted identifier parts at different times. Our new identifier rules should allow legacy systems to easily use
dbo. or other schema prefixes in table names and everything from DDL statements to our schema cache & column reflection will just work.
NATIONAL DEFAULTS: Not new, but all Rails simplified types now default to matching SQL Server "national" or Unicode types. If you need to a non-national type or other special type, we have full column extensions in place. For example, need a
char(24) vs a full length national varying character, just use the
t.char method and proper Rails options in your schema migrations.
The v4.2.0 adapter is now in pre-release and we only have a few issues to track down and fix. Check out the issues in our Github milestone if you are interested in helping. The biggest feature will be turning on foreign key support!
But why stop there? There is so much more to help with. From benchmark and performance tuning, to Database task support. We sure could use your help. For now, give it a try. Thanks!
gem 'activerecord-sqlserver-adapter', '~> 4.2.0.pre'