Created
December 16, 2019 17:39
-
-
Save atomical/b0555b6c3661d8957e0fcfe777bb2934 to your computer and use it in GitHub Desktop.
TinyTDS wrapper for Connection Pool gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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