univedo-shell 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f2197f4b9aac01f855010e84dfa1942d6b8d5b9a
4
+ data.tar.gz: 763e2bab3be02bfcdf54e62baa3c590699484a7b
5
+ SHA512:
6
+ metadata.gz: 6acbb2fbb8af75ebe511e5252f4920bc7cadb4afc6a3bc23adca561b0b0d74fa0bbde345c5d0650e3cb785b376b20d810182e2eb0b919769f98103b5af72dde8
7
+ data.tar.gz: 580bf1842f66f24b5d887fdc0afc4c6ecefdc4427db78426c61f198edaaf3b484c4c6fd8a5c3b50d43988121d0a6b1c77f2dd26941826ce5fe26aa9abd27878c
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in univedo-shell.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Lucas Clemente
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,30 @@
1
+ # Univedo Shell
2
+
3
+ gem install univedo-shell
4
+
5
+ ## Usage
6
+
7
+ ```shell
8
+ univedo-shell <url> <perspective>
9
+ # e.g.
10
+ univedo-shell ws://localhost/f8018f09-fb75-4d3d-8e11-44b2dc796130 468145f2-4ebb-405b-8a42-bcbab94cd0d0
11
+ # Passing a UTS file
12
+ univedo-shell -u path/to/file.uts ws://localhost/f8018f09-fb75-4d3d-8e11-44b2dc796130 468145f2-4ebb-405b-8a42-bcbab94cd0d0
13
+ ```
14
+
15
+ Then just type your SQL queries:
16
+
17
+ ```shell
18
+ $ univedo-shell ws://localhost/f8018f09-fb75-4d3d-8e11-44b2dc796130 468145f2-4ebb-405b-8a42-bcbab94cd0d0
19
+ Connected.
20
+ >> SELECT * FROM people LIMIT 2
21
+ +------------+-----------------+----------------------+----+--------+-----------------------+
22
+ | first_name | home_address_id | home_phone_number_id | id | name | work_email_address_id |
23
+ +------------+-----------------+----------------------+----+--------+-----------------------+
24
+ | Brannon | 1 | 1 | 1 | Welsh | 1 |
25
+ | Alvera | 2 | 2 | 2 | Glover | 2 |
26
+ +------------+-----------------+----------------------+----+--------+-----------------------+
27
+ Completed in 2.69 ms.
28
+ >> q
29
+ $
30
+ ```
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/univedo-shell ADDED
@@ -0,0 +1,120 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.dirname(__FILE__) + "/../lib"
4
+
5
+ require "coolline"
6
+ require "coderay"
7
+ require "terminal-table"
8
+ require "runivedo"
9
+ require "univedo-shell"
10
+ require "optparse"
11
+ require "term/ansicolor"
12
+ require "benchmark"
13
+
14
+ class String
15
+ include Term::ANSIColor
16
+ end
17
+
18
+ #################################
19
+ # Parse options
20
+ #################################
21
+
22
+ options = {}
23
+ op = OptionParser.new do |opts|
24
+ opts.banner = "Usage: univedo-shell [options] <url> <perspective>"
25
+
26
+ opts.on "-u", "--uts [UTS]", "Send UTS file to server" do |path|
27
+ options[:uts] = path
28
+ end
29
+
30
+ opts.on "-h", "--help", "Display this help" do
31
+ puts opts
32
+ exit
33
+ end
34
+ end
35
+ op.parse!
36
+
37
+ if ARGV.count != 2
38
+ puts op
39
+ exit 1
40
+ end
41
+ options[:url] = ARGV.shift
42
+ options[:perspective] = ARGV.shift
43
+
44
+
45
+ #################################
46
+ # Univedo connection
47
+ #################################
48
+
49
+ session = Runivedo::Session.new options[:url], username: "marvin"
50
+ puts "Connected."
51
+ session.apply_uts(File.read(options[:uts])) if options[:uts]
52
+ perspective = session.get_perspective(options[:perspective])
53
+ query = perspective.query
54
+
55
+
56
+ #################################
57
+ # Shell setup
58
+ #################################
59
+
60
+ COMPLETION_ITEMS = (CodeRay::Scanners::SQL::KEYWORDS +
61
+ CodeRay::Scanners::SQL::OBJECTS +
62
+ CodeRay::Scanners::SQL::COMMANDS +
63
+ CodeRay::Scanners::SQL::PREDEFINED_TYPES +
64
+ CodeRay::Scanners::SQL::PREDEFINED_FUNCTIONS +
65
+ CodeRay::Scanners::SQL::DIRECTIVES +
66
+ CodeRay::Scanners::SQL::PREDEFINED_CONSTANTS).map(&:upcase)
67
+
68
+ cool = Coolline.new do |c|
69
+ c.transform_proc = proc do
70
+ CodeRay.scan(c.line, :sql).term
71
+ end
72
+
73
+ c.completion_proc = proc do
74
+ word = c.completed_word.upcase
75
+ COMPLETION_ITEMS.select {|w| w.start_with? word}
76
+ end
77
+ end
78
+
79
+
80
+ #################################
81
+ # Main program
82
+ #################################
83
+
84
+ loop do
85
+ line = cool.readline
86
+ break if line.nil?
87
+ line.strip!
88
+ next if line.empty?
89
+ case line
90
+ when "q", "quit", "exit"
91
+ break
92
+ when "version", "info", "v"
93
+ puts "Univedo Shell #{UnivedoShell::VERSION}"
94
+ puts "(c) 2012-2014 Univedo"
95
+ when "h", "?", "help"
96
+ puts "Just type SQL queries. Quit with 'q'."
97
+ else
98
+ time = Benchmark.realtime do
99
+ begin
100
+ query.prepare(line) do |stmt|
101
+ stmt.execute do |result|
102
+ case
103
+ when id = result.last_inserted_id
104
+ puts "Inserted record with id #{id}".green
105
+ when num = result.num_affected_rows
106
+ puts "#{num} #{num == 1 ? 'row' : 'rows'} affected".green
107
+ else
108
+ rows = result.to_a
109
+ puts Terminal::Table.new rows: rows, headings: stmt.column_names.map(&:bold)
110
+ end
111
+ end
112
+ end
113
+ rescue Runivedo::SqlError => e
114
+ puts e.to_s.strip.red
115
+ end
116
+ end
117
+
118
+ puts "Completed in #{"%.2f" % (time * 1000)} ms."
119
+ end
120
+ end
@@ -0,0 +1,3 @@
1
+ module UnivedoShell
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'univedo-shell'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "univedo-shell"
8
+ spec.version = UnivedoShell::VERSION
9
+ spec.authors = ["Lucas Clemente"]
10
+ spec.email = ["lucas@univedo.com"]
11
+ spec.summary = %q{Simple SQL shell for debugging univedo.}
12
+ spec.homepage = "https://github.com/univedo/univedo-shell"
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 "coolline", "~> 0.4"
21
+ spec.add_dependency "coderay", "~> 1.1"
22
+ spec.add_dependency "terminal-table", "~> 1.4"
23
+ spec.add_dependency "runivedo", "~> 0.1.0"
24
+ spec.add_dependency "term-ansicolor", "~> 1.3"
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.6"
27
+ spec.add_development_dependency "rake"
28
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: univedo-shell
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Lucas Clemente
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: coolline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: coderay
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: terminal-table
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.4'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: runivedo
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: term-ansicolor
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - lucas@univedo.com
114
+ executables:
115
+ - univedo-shell
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - bin/univedo-shell
125
+ - lib/univedo-shell.rb
126
+ - univedo-shell.gemspec
127
+ homepage: https://github.com/univedo/univedo-shell
128
+ licenses:
129
+ - MIT
130
+ metadata: {}
131
+ post_install_message:
132
+ rdoc_options: []
133
+ require_paths:
134
+ - lib
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 2.2.2
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: Simple SQL shell for debugging univedo.
151
+ test_files: []