mysql2xxxx 0.0.3 → 0.0.4
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.
- data/.gitignore +2 -1
- data/Rakefile +2 -0
- data/benchmark/benchmark.rb +71 -0
- data/benchmark/five_thousand_rows.sql.bz2 +0 -0
- data/benchmark/results/0.0.3-20110314153320.txt +46 -0
- data/benchmark/results/0.0.3-20110314160922.txt +185 -0
- data/benchmark/results/0.0.4-20110314190640.txt +147 -0
- data/benchmark/results/0.0.4-20110315110535-ruby18.txt +149 -0
- data/benchmark/results/0.0.4-20110315110613-ruby19.txt +43 -0
- data/benchmark/target.rb +20 -0
- data/lib/mysql2xxxx.rb +8 -5
- data/lib/mysql2xxxx/properties.rb +15 -11
- data/lib/mysql2xxxx/version.rb +1 -1
- data/lib/mysql2xxxx/writer.rb +82 -0
- data/lib/mysql2xxxx/writer/csv.rb +17 -0
- data/lib/mysql2xxxx/writer/json.rb +29 -0
- data/lib/mysql2xxxx/{xml.rb → writer/xml.rb} +7 -13
- data/mysql2xxxx.gemspec +3 -1
- data/test/helper.rb +3 -1
- data/test/test_active_record_config_stealing.rb +1 -1
- data/test/test_multiline_sql.rb +19 -0
- data/test/test_mysql2xxxx.rb +7 -3
- metadata +24 -51
- data/lib/mysql2xxxx/csv.rb +0 -32
- data/lib/mysql2xxxx/extra_outputs.rb +0 -23
- data/lib/mysql2xxxx/json.rb +0 -36
data/mysql2xxxx.gemspec
CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.require_paths = ["lib"]
|
21
21
|
|
22
22
|
s.add_dependency 'activesupport', '>=2.3.10'
|
23
|
-
s.add_dependency '
|
23
|
+
s.add_dependency 'mysql'
|
24
24
|
s.add_dependency 'mixlib-cli'
|
25
25
|
s.add_dependency 'fast_xs'
|
26
26
|
unless RUBY_VERSION >= '1.9'
|
@@ -29,9 +29,11 @@ Gem::Specification.new do |s|
|
|
29
29
|
|
30
30
|
s.add_development_dependency 'activerecord'
|
31
31
|
s.add_development_dependency 'shell-executer'
|
32
|
+
s.add_development_dependency 'posix-spawn'
|
32
33
|
if RUBY_VERSION >= '1.9'
|
33
34
|
s.add_development_dependency 'ruby-debug19'
|
34
35
|
else
|
36
|
+
s.add_development_dependency 'memprof'
|
35
37
|
s.add_development_dependency 'ruby-debug'
|
36
38
|
end
|
37
39
|
end
|
data/test/helper.rb
CHANGED
@@ -12,6 +12,7 @@ require 'mysql2xxxx'
|
|
12
12
|
|
13
13
|
MYSQL_USER = 'root'
|
14
14
|
MYSQL_PASS = 'password'
|
15
|
+
MYSQL_HOST = '127.0.0.1'
|
15
16
|
TEST_DB = 'mysql2xxxx_test'
|
16
17
|
|
17
18
|
def execute_sql(sql, db = 'mysql')
|
@@ -29,7 +30,8 @@ class Test::Unit::TestCase
|
|
29
30
|
:execute => %{SELECT * FROM automobile_makes WHERE automobile_makes.name IN (SELECT DISTINCT automobile_make_years.make_name FROM automobile_make_years)},
|
30
31
|
:user => MYSQL_USER,
|
31
32
|
:password => MYSQL_PASS,
|
32
|
-
:database => TEST_DB
|
33
|
+
:database => TEST_DB,
|
34
|
+
:host => MYSQL_HOST
|
33
35
|
}
|
34
36
|
end
|
35
37
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMultilineSql < Test::Unit::TestCase
|
4
|
+
def test_multiline_sql
|
5
|
+
a = Mysql2xxxx::JSON.new @options.merge(:execute => %{
|
6
|
+
DROP TABLE IF EXISTS t1; CREATE TEMPORARY TABLE t1 SELECT CONCAT_WS('-', year, make_name) AS crazy_name FROM automobile_make_years; SELECT * FROM t1
|
7
|
+
})
|
8
|
+
str = a.to_s
|
9
|
+
assert str.include?('2002-Acura')
|
10
|
+
end
|
11
|
+
def test_multiline_sql_with_ending_semicolon
|
12
|
+
a = Mysql2xxxx::JSON.new @options.merge(:execute => %{
|
13
|
+
DROP TABLE IF EXISTS t1; CREATE TEMPORARY TABLE t1 SELECT CONCAT_WS('-', year, make_name) AS crazy_name FROM automobile_make_years; SELECT * FROM t1
|
14
|
+
;
|
15
|
+
})
|
16
|
+
str = a.to_s
|
17
|
+
assert str.include?('2002-Acura')
|
18
|
+
end
|
19
|
+
end
|
data/test/test_mysql2xxxx.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
1
2
|
require 'helper'
|
2
3
|
|
3
4
|
class TestMysql2xxxx < Test::Unit::TestCase
|
4
|
-
def
|
5
|
+
def test_1_mysql2json
|
5
6
|
a = Mysql2xxxx::JSON.new @options
|
6
7
|
str = a.to_s
|
7
8
|
assert str.include?('Acura')
|
9
|
+
assert str.include?('Citro\\u00ebn')
|
8
10
|
assert !str.include?('DaimlerChrysler')
|
9
11
|
end
|
10
12
|
|
11
|
-
def
|
13
|
+
def test_2_mysql2csv
|
12
14
|
a = Mysql2xxxx::CSV.new @options
|
13
15
|
str = a.to_s
|
14
16
|
assert str.include?('Acura')
|
17
|
+
assert str.include?('Citroën')
|
15
18
|
assert !str.include?('DaimlerChrysler')
|
16
19
|
end
|
17
20
|
|
18
|
-
def
|
21
|
+
def test_3_mysql2xml
|
19
22
|
a = Mysql2xxxx::XML.new @options
|
20
23
|
str = a.to_s
|
21
24
|
assert str.include?('Acura')
|
25
|
+
assert str.include?('Citroën')
|
22
26
|
assert !str.include?('DaimlerChrysler')
|
23
27
|
end
|
24
28
|
end
|
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mysql2xxxx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Seamus Abshere
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-03-15 00:00:00 -05:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,25 +21,17 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 23
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 3
|
33
|
-
- 10
|
34
24
|
version: 2.3.10
|
35
25
|
type: :runtime
|
36
26
|
version_requirements: *id001
|
37
27
|
- !ruby/object:Gem::Dependency
|
38
|
-
name:
|
28
|
+
name: mysql
|
39
29
|
prerelease: false
|
40
30
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
31
|
none: false
|
42
32
|
requirements:
|
43
33
|
- - ">="
|
44
34
|
- !ruby/object:Gem::Version
|
45
|
-
hash: 3
|
46
|
-
segments:
|
47
|
-
- 0
|
48
35
|
version: "0"
|
49
36
|
type: :runtime
|
50
37
|
version_requirements: *id002
|
@@ -56,9 +43,6 @@ dependencies:
|
|
56
43
|
requirements:
|
57
44
|
- - ">="
|
58
45
|
- !ruby/object:Gem::Version
|
59
|
-
hash: 3
|
60
|
-
segments:
|
61
|
-
- 0
|
62
46
|
version: "0"
|
63
47
|
type: :runtime
|
64
48
|
version_requirements: *id003
|
@@ -70,65 +54,50 @@ dependencies:
|
|
70
54
|
requirements:
|
71
55
|
- - ">="
|
72
56
|
- !ruby/object:Gem::Version
|
73
|
-
hash: 3
|
74
|
-
segments:
|
75
|
-
- 0
|
76
57
|
version: "0"
|
77
58
|
type: :runtime
|
78
59
|
version_requirements: *id004
|
79
60
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
61
|
+
name: activerecord
|
81
62
|
prerelease: false
|
82
63
|
requirement: &id005 !ruby/object:Gem::Requirement
|
83
64
|
none: false
|
84
65
|
requirements:
|
85
66
|
- - ">="
|
86
67
|
- !ruby/object:Gem::Version
|
87
|
-
hash: 3
|
88
|
-
segments:
|
89
|
-
- 0
|
90
68
|
version: "0"
|
91
|
-
type: :
|
69
|
+
type: :development
|
92
70
|
version_requirements: *id005
|
93
71
|
- !ruby/object:Gem::Dependency
|
94
|
-
name:
|
72
|
+
name: shell-executer
|
95
73
|
prerelease: false
|
96
74
|
requirement: &id006 !ruby/object:Gem::Requirement
|
97
75
|
none: false
|
98
76
|
requirements:
|
99
77
|
- - ">="
|
100
78
|
- !ruby/object:Gem::Version
|
101
|
-
hash: 3
|
102
|
-
segments:
|
103
|
-
- 0
|
104
79
|
version: "0"
|
105
80
|
type: :development
|
106
81
|
version_requirements: *id006
|
107
82
|
- !ruby/object:Gem::Dependency
|
108
|
-
name:
|
83
|
+
name: posix-spawn
|
109
84
|
prerelease: false
|
110
85
|
requirement: &id007 !ruby/object:Gem::Requirement
|
111
86
|
none: false
|
112
87
|
requirements:
|
113
88
|
- - ">="
|
114
89
|
- !ruby/object:Gem::Version
|
115
|
-
hash: 3
|
116
|
-
segments:
|
117
|
-
- 0
|
118
90
|
version: "0"
|
119
91
|
type: :development
|
120
92
|
version_requirements: *id007
|
121
93
|
- !ruby/object:Gem::Dependency
|
122
|
-
name: ruby-
|
94
|
+
name: ruby-debug19
|
123
95
|
prerelease: false
|
124
96
|
requirement: &id008 !ruby/object:Gem::Requirement
|
125
97
|
none: false
|
126
98
|
requirements:
|
127
99
|
- - ">="
|
128
100
|
- !ruby/object:Gem::Version
|
129
|
-
hash: 3
|
130
|
-
segments:
|
131
|
-
- 0
|
132
101
|
version: "0"
|
133
102
|
type: :development
|
134
103
|
version_requirements: *id008
|
@@ -148,17 +117,25 @@ files:
|
|
148
117
|
- Gemfile
|
149
118
|
- README.rdoc
|
150
119
|
- Rakefile
|
120
|
+
- benchmark/benchmark.rb
|
121
|
+
- benchmark/five_thousand_rows.sql.bz2
|
122
|
+
- benchmark/results/0.0.3-20110314153320.txt
|
123
|
+
- benchmark/results/0.0.3-20110314160922.txt
|
124
|
+
- benchmark/results/0.0.4-20110314190640.txt
|
125
|
+
- benchmark/results/0.0.4-20110315110535-ruby18.txt
|
126
|
+
- benchmark/results/0.0.4-20110315110613-ruby19.txt
|
127
|
+
- benchmark/target.rb
|
151
128
|
- bin/mysql2csv
|
152
129
|
- bin/mysql2json
|
153
130
|
- bin/mysql2xml
|
154
131
|
- lib/mysql2xxxx.rb
|
155
132
|
- lib/mysql2xxxx/cli.rb
|
156
|
-
- lib/mysql2xxxx/csv.rb
|
157
|
-
- lib/mysql2xxxx/extra_outputs.rb
|
158
|
-
- lib/mysql2xxxx/json.rb
|
159
133
|
- lib/mysql2xxxx/properties.rb
|
160
134
|
- lib/mysql2xxxx/version.rb
|
161
|
-
- lib/mysql2xxxx/
|
135
|
+
- lib/mysql2xxxx/writer.rb
|
136
|
+
- lib/mysql2xxxx/writer/csv.rb
|
137
|
+
- lib/mysql2xxxx/writer/json.rb
|
138
|
+
- lib/mysql2xxxx/writer/xml.rb
|
162
139
|
- mysql2xxxx.gemspec
|
163
140
|
- test/fixtures/automobile_make_years.sql
|
164
141
|
- test/fixtures/automobile_makes.sql
|
@@ -166,6 +143,7 @@ files:
|
|
166
143
|
- test/test_active_record_config_stealing.rb
|
167
144
|
- test/test_cli.rb
|
168
145
|
- test/test_extra_outputs.rb
|
146
|
+
- test/test_multiline_sql.rb
|
169
147
|
- test/test_mysql2xxxx.rb
|
170
148
|
- test/test_well_formedness.rb
|
171
149
|
has_rdoc: true
|
@@ -182,23 +160,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
160
|
requirements:
|
183
161
|
- - ">="
|
184
162
|
- !ruby/object:Gem::Version
|
185
|
-
hash: 3
|
186
|
-
segments:
|
187
|
-
- 0
|
188
163
|
version: "0"
|
189
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
165
|
none: false
|
191
166
|
requirements:
|
192
167
|
- - ">="
|
193
168
|
- !ruby/object:Gem::Version
|
194
|
-
hash: 3
|
195
|
-
segments:
|
196
|
-
- 0
|
197
169
|
version: "0"
|
198
170
|
requirements: []
|
199
171
|
|
200
172
|
rubyforge_project: mysql2xxxx
|
201
|
-
rubygems_version: 1.
|
173
|
+
rubygems_version: 1.6.2
|
202
174
|
signing_key:
|
203
175
|
specification_version: 3
|
204
176
|
summary: In a memory-sensitive way (but not fast), dump mysql tables to JSON, CSV, XML.
|
@@ -209,5 +181,6 @@ test_files:
|
|
209
181
|
- test/test_active_record_config_stealing.rb
|
210
182
|
- test/test_cli.rb
|
211
183
|
- test/test_extra_outputs.rb
|
184
|
+
- test/test_multiline_sql.rb
|
212
185
|
- test/test_mysql2xxxx.rb
|
213
186
|
- test/test_well_formedness.rb
|
data/lib/mysql2xxxx/csv.rb
DELETED
@@ -1,32 +0,0 @@
|
|
1
|
-
if RUBY_VERSION >= '1.9'
|
2
|
-
require 'csv'
|
3
|
-
else
|
4
|
-
require 'fastercsv'
|
5
|
-
end
|
6
|
-
|
7
|
-
module Mysql2xxxx
|
8
|
-
class CSV
|
9
|
-
include ExtraOutputs
|
10
|
-
|
11
|
-
attr_reader :properties
|
12
|
-
|
13
|
-
def initialize(options = {})
|
14
|
-
@properties = Properties.new options
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_file(f)
|
18
|
-
@client = ::Mysql2::Client.new properties.database_config
|
19
|
-
keys = nil
|
20
|
-
@client.query(properties.execute).each do |hsh|
|
21
|
-
unless keys
|
22
|
-
keys = hsh.keys
|
23
|
-
f.write keys.to_csv
|
24
|
-
end
|
25
|
-
f.write keys.inject([]) { |memo, k| memo.push hsh[k] }.to_csv
|
26
|
-
end
|
27
|
-
nil
|
28
|
-
ensure
|
29
|
-
@client.try :close
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'stringio'
|
2
|
-
module Mysql2xxxx
|
3
|
-
module ExtraOutputs
|
4
|
-
def to_s
|
5
|
-
s = ::StringIO.new
|
6
|
-
to_file s
|
7
|
-
s.rewind
|
8
|
-
s.read
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_stdout
|
12
|
-
to_file $stdout
|
13
|
-
nil
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_path(path)
|
17
|
-
f = ::File.open(path, 'w')
|
18
|
-
to_file f
|
19
|
-
f.close
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
data/lib/mysql2xxxx/json.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
%w{
|
2
|
-
active_support/json/encoding
|
3
|
-
}.each do |active_support_3_requirement|
|
4
|
-
require active_support_3_requirement
|
5
|
-
end if ::ActiveSupport::VERSION::MAJOR == 3
|
6
|
-
|
7
|
-
module Mysql2xxxx
|
8
|
-
class JSON
|
9
|
-
include ExtraOutputs
|
10
|
-
|
11
|
-
attr_reader :properties
|
12
|
-
|
13
|
-
def initialize(options = {})
|
14
|
-
@properties = Properties.new options
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_file(f)
|
18
|
-
@client = ::Mysql2::Client.new properties.database_config
|
19
|
-
first = true
|
20
|
-
f.write '['
|
21
|
-
@client.query(properties.execute).each do |hsh|
|
22
|
-
line = if first
|
23
|
-
first = false
|
24
|
-
hsh.to_json
|
25
|
-
else
|
26
|
-
',' + hsh.to_json
|
27
|
-
end
|
28
|
-
f.write line
|
29
|
-
end
|
30
|
-
f.write ']'
|
31
|
-
nil
|
32
|
-
ensure
|
33
|
-
@client.try :close
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|