itds 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/bin/itds +6 -0
- data/itds.gemspec +25 -0
- data/lib/itds.rb +3 -0
- data/lib/itds/client.rb +27 -0
- data/lib/itds/repl.rb +116 -0
- data/lib/itds/version.rb +3 -0
- metadata +123 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Andrew Liu
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Itds
|
2
|
+
|
3
|
+
A very simple SQL server CLI tools just to ease the developer working on Mac or Linux.
|
4
|
+
|
5
|
+
# Usage
|
6
|
+
|
7
|
+
Help
|
8
|
+
```
|
9
|
+
$itds --help
|
10
|
+
```
|
11
|
+
|
12
|
+
Command parameters:
|
13
|
+
```
|
14
|
+
$itds -h <hostname> -P <password> -u <username> -d <contained_database> [SQL]
|
15
|
+
```
|
16
|
+
|
17
|
+
Execute a command
|
18
|
+
```
|
19
|
+
$itds -h <hostname> -d <database> select 1
|
20
|
+
+---+
|
21
|
+
|
22
|
+
+---+
|
23
|
+
| 1 |
|
24
|
+
+---+
|
25
|
+
```
|
26
|
+
|
27
|
+
Interactive mode
|
28
|
+
```
|
29
|
+
$itds -h <hostname> -d <mydb>
|
30
|
+
mydb> select(1)
|
31
|
+
+---+
|
32
|
+
|
33
|
+
+---+
|
34
|
+
| 1 |
|
35
|
+
+---+
|
36
|
+
mydb> exit
|
37
|
+
$
|
38
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/itds
ADDED
data/itds.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'itds/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "itds"
|
8
|
+
spec.version = Itds::VERSION
|
9
|
+
spec.authors = ["Andrew Liu"]
|
10
|
+
spec.email = ["liusandrew@gmail.com"]
|
11
|
+
spec.summary = %q{A very simple SQL server client.}
|
12
|
+
spec.homepage = "http://github.com/andl/itds"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency "tiny_tds", "~> 0.6.2"
|
21
|
+
spec.add_dependency "terminal-table", "~> 1.4.5"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
end
|
data/lib/itds.rb
ADDED
data/lib/itds/client.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "forwardable"
|
2
|
+
require "tiny_tds"
|
3
|
+
|
4
|
+
# simple TinyTDS client wrapper
|
5
|
+
module Itds
|
6
|
+
class Client
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :@backend, :close
|
9
|
+
|
10
|
+
DEFAULT_OPTS = {
|
11
|
+
port: 1433,
|
12
|
+
username: 'sa',
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize(opts={})
|
16
|
+
opts = DEFAULT_OPTS.merge(opts)
|
17
|
+
opts[:azure] = true if(opts[:database])
|
18
|
+
|
19
|
+
@backend = TinyTds::Client.new(opts)
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute(sql)
|
23
|
+
res = @backend.execute(sql)
|
24
|
+
res
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/itds/repl.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "optparse"
|
2
|
+
require 'terminal-table'
|
3
|
+
require 'readline'
|
4
|
+
|
5
|
+
module Itds
|
6
|
+
class Repl
|
7
|
+
class << self
|
8
|
+
def config(options)
|
9
|
+
@options = options
|
10
|
+
@client = Client.new(options)
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def run
|
15
|
+
while cmd = Readline.readline(prompt, true)
|
16
|
+
execute_cmd(cmd)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def prompt
|
21
|
+
@prompt ||= "#{@options[:database]}> "
|
22
|
+
end
|
23
|
+
|
24
|
+
def execute_cmd(cmd)
|
25
|
+
begin
|
26
|
+
stop if cmd == "exit"
|
27
|
+
res = @client.execute(cmd)
|
28
|
+
print_result(res)
|
29
|
+
rescue => e
|
30
|
+
print_err(e)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def print_result(res)
|
35
|
+
fields = res.fields
|
36
|
+
rows = []
|
37
|
+
res.each do |rowset|
|
38
|
+
rows << rowset.values
|
39
|
+
end
|
40
|
+
|
41
|
+
t = Terminal::Table.new :headings => fields, :rows => rows
|
42
|
+
puts t
|
43
|
+
end
|
44
|
+
|
45
|
+
def print_err(err)
|
46
|
+
puts "Error: #{err.message}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def stop
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
class ReplRunner
|
57
|
+
def self.run(args=[])
|
58
|
+
options = {}
|
59
|
+
mandatory = [:host]
|
60
|
+
|
61
|
+
opts_parser = OptionParser.new do |opts|
|
62
|
+
opts.banner = "Usage: itds [options] [sql]"
|
63
|
+
|
64
|
+
opts.on("-h", "--host HOST", "host or ip") do |h|
|
65
|
+
options[:host] = h
|
66
|
+
end
|
67
|
+
|
68
|
+
opts.on("-p", "--port [PORT]", Integer, "port number, default is 1433") do |p|
|
69
|
+
options[:port] = p
|
70
|
+
end
|
71
|
+
|
72
|
+
opts.on("-u", "--user [USER]", "username") do |u|
|
73
|
+
options[:username] = u
|
74
|
+
end
|
75
|
+
|
76
|
+
opts.on("-d", "--database [DATABASE]", "database name") do |d|
|
77
|
+
options[:database] = d
|
78
|
+
end
|
79
|
+
|
80
|
+
opts.on("-P", "--password [PASSWORD]", "optional password") do |p|
|
81
|
+
options[:password] = p
|
82
|
+
end
|
83
|
+
|
84
|
+
opts.on_tail("--help", "show this help message") do
|
85
|
+
puts opts
|
86
|
+
exit
|
87
|
+
end
|
88
|
+
|
89
|
+
opts.on_tail("--version", "show version") do
|
90
|
+
puts Itds::VERSION
|
91
|
+
exit
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
if args.empty?
|
96
|
+
puts opts_parser.help
|
97
|
+
exit
|
98
|
+
end
|
99
|
+
|
100
|
+
opts_parser.parse!(args)
|
101
|
+
missing = mandatory.select {|p| options[p].nil? }
|
102
|
+
unless missing.empty?
|
103
|
+
puts "Missing mandatory options: #{missing.join(', ')}"
|
104
|
+
exit
|
105
|
+
end
|
106
|
+
|
107
|
+
Repl.config(options)
|
108
|
+
if args.empty?
|
109
|
+
trap("INT") { exit }
|
110
|
+
Repl.run
|
111
|
+
else
|
112
|
+
Repl.execute_cmd(args.join(" "))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/itds/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: itds
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andrew Liu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-05-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: tiny_tds
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.6.2
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.6.2
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: terminal-table
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 1.4.5
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.5
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: bundler
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '1.5'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.5'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: rake
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
description:
|
79
|
+
email:
|
80
|
+
- liusandrew@gmail.com
|
81
|
+
executables:
|
82
|
+
- itds
|
83
|
+
extensions: []
|
84
|
+
extra_rdoc_files: []
|
85
|
+
files:
|
86
|
+
- .gitignore
|
87
|
+
- Gemfile
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/itds
|
92
|
+
- itds.gemspec
|
93
|
+
- lib/itds.rb
|
94
|
+
- lib/itds/client.rb
|
95
|
+
- lib/itds/repl.rb
|
96
|
+
- lib/itds/version.rb
|
97
|
+
homepage: http://github.com/andl/itds
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.23
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: A very simple SQL server client.
|
122
|
+
test_files: []
|
123
|
+
has_rdoc:
|