Best Ruby ORM to pack around an old SQL Server database?

I found this answer and it looks like what I am doing. I heard mixed answers about whether datamapper can support SQL Server through data objects. Basically, we have an application that uses a sequentially structured database, sequentially named tables, etc. In SQL Server. We make all kinds of tools and materials that should interact with it, some of them are removed, and so I decided that we need to create some common, simple access point for read / write operations in the SQL Server application, since this API is all C # and other things that I despise.

Now I have a question, does anyone have examples or projects that they know about where Ruby ORM can essentially create models for another old application database, defining conventions for each model pkeys, fkeys, table names, etc. . Sequel is the only ORM I've used with SQL Server, but I have never done anything like it. Any suggestions?

+4
source share
3 answers

Sequel does not automatically create models, but you could write an extension that outputs Sequel :: Database # and Sequel :: Database # schema (for each table) and did some key analysis and table names to guess the associations. The reason Sequel does not do this by default is that in all cases it is impossible to do it right. But if your database always follows certain conventions, you can certainly make it work.

+2
source

I can’t give you a fully processed example, since I just started working with Ruby with MS SQL Server, but based on my experience and you said, I would suggest using the model tool Sequel.

Sequel definitely supports and tests on MS SQL Server, but the situation seems a little less clear with Active Record. I have not used DataMapper, so I can not comment on this. As far as I know, the only ORMs for Ruby are DataMapper, Sequel, Active Record 2 and Active Relation / Active Record 3 (new material for accessing Rails 3 data).

There is an Active Record adapter for MS SQL , but for me this did not work with MRI 1.8.7. Microsoft's IronRuby team uses the version of this adapter to run IronRuby on Rails with MS SQL Server, so you can try using Active Record to combine IronRuby. IronRuby is currently in the Release Candidate phase, so this should work, although there are still many bug fixes available.

+1
source

ActiveRecord is one option that should be able to do what you describe.

So this should be possible:

class Order < ActiveRecord::Base establish_connection { #a hash describing your SQL Server connection attributes } set_table_name 'PRODUCT_ORDER' # or whatever set_primary_key :PROD_ORD_ID has_many :order_lines end class OrderLine < ActiveRecord::Base establish_connection { #as above } set_table_name 'ORDER_LINE' belongs_to :order has_many :products # etc... end order = Order.first order.order_lines.each { |line| puts line } 
0
source

Source: https://habr.com/ru/post/1303917/


All Articles