Created
June 15, 2013 21:49
-
-
Save deoxxa/5789699 to your computer and use it in GitHub Desktop.
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
#!/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