Skip to content

Instantly share code, notes, and snippets.

@deoxxa
Created June 15, 2013 21:49
Show Gist options
  • Save deoxxa/5789699 to your computer and use it in GitHub Desktop.
Save deoxxa/5789699 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
RAILS_ROOT = File.expand_path '../..', __FILE__
require "rubygems"
require "yaml"
require "tiny_tds"
require "singleton"
class Connection
include Singleton
def initialize
@client = TinyTds::Client.new config
end
def query sql
@client.execute sql
end
private
def config
hash = YAML.load(File.read("#{RAILS_ROOT}/config/e21.yml"))
hash.keys.each do |key|
hash[key.to_sym] = hash.delete(key)
end
hash
end
end
class Repl
include Singleton
def initialize
@connection = Connection.instance
end
def process input
result = @connection.query input
result.each { |row| output row }
result.cancel
end
def output row
puts row
end
end
# let's run it
loop do
print "e21> "
Repl.instance.process gets.chomp!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment