Skip to content

Instantly share code, notes, and snippets.

@atomical
Created December 16, 2019 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atomical/b0555b6c3661d8957e0fcfe777bb2934 to your computer and use it in GitHub Desktop.
Save atomical/b0555b6c3661d8957e0fcfe777bb2934 to your computer and use it in GitHub Desktop.
TinyTDS wrapper for Connection Pool gem
class TinyTdsWrapper
def initialize(config)
@config = config
@client = nil
end
def method_missing(method_name, *args, &block)
connect!
begin
@client.send(method_name, *args, &block)
rescue TinyTds::Error => e
disconnect!
raise e
end
end
def connect!
disconnect! unless active?
@client ||= TinyTds::Client.new(@config)
end
def disconnect!
@client.close if @client
@client = nil
end
def active?
@client && @client.active?
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment