myq 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4f38739131d0ebeb2a2f1d6916479cc036b5525b
4
+ data.tar.gz: 07a7103c7c1a4c80cfc1a7f2bea65269911498f7
5
+ SHA512:
6
+ metadata.gz: 7d98a0acbccf7c330b9c68547359489dddaa50b9b16d8e0c12cb54080225ce2e79ebbff3560d3992e08cd867b1a6b0c14bd974576d9385d8dcf59ee10ad354b5
7
+ data.tar.gz: d04fd79824a9c7a3ff9cbb4ab20f4e559736a313b2ff484ff02ba404fcd297a3bf314ce19937efe1a5e6e4095bc8baa73c161554be5d824018e0ce8a5b4b3298
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in myq.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 toyama0919
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,48 @@
1
+ # Myq
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'myq'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install myq
18
+
19
+ ## Setting
20
+
21
+ Create $HOME/.database.yml
22
+ ```yml
23
+ default:
24
+ database: test
25
+ host: localhost
26
+ port: 3306
27
+ username: root
28
+ password: ''
29
+
30
+ staging:
31
+ database: test
32
+ host: staging.net
33
+ port: 3306
34
+ username: root
35
+ password: ''
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ TODO: Write usage instructions here
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it ( http://github.com/<my-github-username>/myq/fork )
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/myq ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require 'myq'
4
+ Myq::Commands.start
data/lib/myq.rb ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require "myq/version"
4
+ require "myq/commands"
@@ -0,0 +1,74 @@
1
+ #!/usr/bin/env ruby
2
+ # coding: utf-8
3
+ require 'thor'
4
+ require 'mysql2-cs-bind'
5
+ require 'yajl'
6
+ require 'yaml'
7
+
8
+ module Myq
9
+ class Commands < Thor
10
+ class_option :host, aliases: '-h', type: :string, default: 'localhost', desc: 'host'
11
+ class_option :username, aliases: '-u', type: :string, default: 'root', desc: 'username'
12
+ class_option :password, aliases: '-p', type: :string, default: '', desc: 'password'
13
+ class_option :port, type: :numeric, default: 3306, desc: 'port'
14
+ class_option :database, aliases: '-d', type: :string, desc: 'database'
15
+ class_option :profile, aliases: '--pr', type: :string, default: 'default', desc: 'profile by .database.yml'
16
+ map '-q' => :query_inline
17
+ map '-f' => :query_file
18
+ map '-s' => :sample
19
+ map '-v' => :version
20
+
21
+ def initialize(args = [], options = {}, config = {})
22
+ super(args, options, config)
23
+ global_options = config[:shell].base.options
24
+ if File.exist?("#{ENV['HOME']}/.database.yml")
25
+ data = YAML.load_file("#{ENV['HOME']}/.database.yml")[global_options['profile']]
26
+ host = data['host']
27
+ username = data['username']
28
+ password = data['password']
29
+ database = data['database']
30
+ port = data['port']
31
+ else
32
+ host = global_options['host']
33
+ username = global_options['username']
34
+ password = global_options['password']
35
+ database = global_options['database']
36
+ port = global_options['port']
37
+ end
38
+ @client = Mysql2::Client.new(host: host, username: username, password: password, database: database, port: port)
39
+ end
40
+
41
+ desc "-q [sql]", "inline query"
42
+ def query_inline(query)
43
+ query(query)
44
+ end
45
+
46
+ desc "-f [file]", "query by sql file"
47
+ def query_file(file)
48
+ query(File.read(file))
49
+ end
50
+
51
+ desc "-s [table name]", "sampling query, default limit 10"
52
+ option :limit, type: :numeric, default: 10, aliases: '-n', desc: 'limit count'
53
+ def sample(table)
54
+ query("select * from #{table} limit #{options['limit']}")
55
+ end
56
+
57
+ desc "version", "show version"
58
+ def version
59
+ puts VERSION
60
+ end
61
+
62
+ private
63
+
64
+ def query(query)
65
+ result = []
66
+ query.split(';').each do |sql|
67
+ res = @client.xquery(sql)
68
+ res.each do |record|
69
+ puts Yajl::Encoder.encode(record)
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ module Myq
2
+ VERSION = "0.0.1"
3
+ end
data/myq.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'myq/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "myq"
8
+ spec.version = Myq::VERSION
9
+ spec.authors = ["toyama0919"]
10
+ spec.email = ["toyama0919@gmail.com"]
11
+ spec.summary = %q{Command-line MYSQL TO JSON processor.}
12
+ spec.description = %q{Command-line MYSQL TO JSON processor.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_runtime_dependency "thor"
24
+ spec.add_runtime_dependency "yajl-ruby"
25
+ spec.add_runtime_dependency "mysql2-cs-bind"
26
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: myq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - toyama0919
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: thor
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yajl-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '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'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2-cs-bind
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Command-line MYSQL TO JSON processor.
84
+ email:
85
+ - toyama0919@gmail.com
86
+ executables:
87
+ - myq
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - bin/myq
97
+ - lib/myq.rb
98
+ - lib/myq/commands.rb
99
+ - lib/myq/version.rb
100
+ - myq.gemspec
101
+ homepage: ''
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.2.2
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Command-line MYSQL TO JSON processor.
125
+ test_files: []