class User < ActiveRecord::Base
# 默认连 mysql
end
class AnotherModel < SqlServerBaseModel
#链接的是 SQL Server
end
init/speed_up_sql_server.rb
# 加上下面的内容会执行 SQL语句更快,否则大量查询时, SQL Server会出现性能问题。
# Speed up SQL Server Query
ActiveRecord::ConnectionAdapters::SQLServer::DatabaseStatements.class_eval do
def execute_sp_executesql(sql)
proc_name = "sp_executesql #{quote(sql)}"
result = execute_procedure(proc_name)
return result
end
def execute_sp_executesql_noexception(sql)
begin
execute_sp_executesql(sql)
rescue => e
return nil
end
end
def select(sql, name = nil, binds = [])
exec_query(sql, name, binds)
end
end