ch-client 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +7 -0
  2. data/.codeclimate.yml +22 -0
  3. data/.gitignore +9 -0
  4. data/.travis.yml +3 -0
  5. data/CHANGELOG.md +58 -0
  6. data/Gemfile +3 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +262 -0
  9. data/Rakefile +15 -0
  10. data/VERSION +1 -0
  11. data/bin/clickhouse +9 -0
  12. data/clickhouse.gemspec +36 -0
  13. data/lib/clickhouse.rb +60 -0
  14. data/lib/clickhouse/cli.rb +46 -0
  15. data/lib/clickhouse/cli/client.rb +149 -0
  16. data/lib/clickhouse/cli/console.rb +73 -0
  17. data/lib/clickhouse/cli/server.rb +37 -0
  18. data/lib/clickhouse/cli/server/assets/css/clickhouse.css +177 -0
  19. data/lib/clickhouse/cli/server/assets/css/codemirror.css +341 -0
  20. data/lib/clickhouse/cli/server/assets/css/datatables.css +1 -0
  21. data/lib/clickhouse/cli/server/assets/css/normalize.css +427 -0
  22. data/lib/clickhouse/cli/server/assets/css/skeleton.css +418 -0
  23. data/lib/clickhouse/cli/server/assets/js/clickhouse.js +188 -0
  24. data/lib/clickhouse/cli/server/assets/js/codemirror.js +9096 -0
  25. data/lib/clickhouse/cli/server/assets/js/datatables.js +166 -0
  26. data/lib/clickhouse/cli/server/assets/js/disableswipeback.js +97 -0
  27. data/lib/clickhouse/cli/server/assets/js/jquery.js +11015 -0
  28. data/lib/clickhouse/cli/server/assets/js/sql.js +232 -0
  29. data/lib/clickhouse/cli/server/views/index.erb +46 -0
  30. data/lib/clickhouse/cluster.rb +43 -0
  31. data/lib/clickhouse/connection.rb +42 -0
  32. data/lib/clickhouse/connection/client.rb +135 -0
  33. data/lib/clickhouse/connection/logger.rb +12 -0
  34. data/lib/clickhouse/connection/query.rb +160 -0
  35. data/lib/clickhouse/connection/query/result_row.rb +36 -0
  36. data/lib/clickhouse/connection/query/result_set.rb +103 -0
  37. data/lib/clickhouse/connection/query/table.rb +50 -0
  38. data/lib/clickhouse/error.rb +18 -0
  39. data/lib/clickhouse/utils.rb +23 -0
  40. data/lib/clickhouse/version.rb +7 -0
  41. data/script/console +58 -0
  42. data/test/test_helper.rb +15 -0
  43. data/test/test_helper/coverage.rb +16 -0
  44. data/test/test_helper/minitest.rb +13 -0
  45. data/test/test_helper/simple_connection.rb +12 -0
  46. data/test/unit/connection/query/test_result_row.rb +36 -0
  47. data/test/unit/connection/query/test_result_set.rb +196 -0
  48. data/test/unit/connection/query/test_table.rb +39 -0
  49. data/test/unit/connection/test_client.rb +206 -0
  50. data/test/unit/connection/test_cluster.rb +81 -0
  51. data/test/unit/connection/test_logger.rb +35 -0
  52. data/test/unit/connection/test_query.rb +410 -0
  53. data/test/unit/test_clickhouse.rb +99 -0
  54. data/test/unit/test_connection.rb +55 -0
  55. data/test/unit/test_utils.rb +39 -0
  56. metadata +326 -0
@@ -0,0 +1,99 @@
1
+ require_relative "../test_helper"
2
+
3
+ module Unit
4
+ class TestClickhouse < MiniTest::Test
5
+
6
+ describe Clickhouse do
7
+ it "has the current version" do
8
+ version = File.read(path("VERSION")).strip
9
+ assert_equal version, Clickhouse::VERSION
10
+ assert File.read(path "CHANGELOG.md").include?("Version #{version} ")
11
+ end
12
+
13
+ describe ".logger=" do
14
+ it "stores the passed value as the instance variable :@logger" do
15
+ Clickhouse.logger = (logger = mock)
16
+ assert_equal logger, Clickhouse.instance_variable_get(:@logger)
17
+ end
18
+ end
19
+
20
+ describe ".logger" do
21
+ it "returns its instance variable :@logger" do
22
+ Clickhouse.instance_variable_set :@logger, (logger = mock)
23
+ assert_equal logger, Clickhouse.logger
24
+ end
25
+ end
26
+
27
+ describe ".configurations=" do
28
+ it "stores the passed hash as the instance variable :@configurations" do
29
+ Clickhouse.configurations = (configurations = {})
30
+ assert_equal configurations, Clickhouse.instance_variable_get(:@configurations)
31
+ end
32
+
33
+ it "stringifies the passed hash" do
34
+ Clickhouse.configurations = {:a => "b"}
35
+ assert_equal({"a" => "b"}, Clickhouse.instance_variable_get(:@configurations))
36
+ end
37
+ end
38
+
39
+ describe ".configurations" do
40
+ it "returns its instance variable :@configurations" do
41
+ Clickhouse.instance_variable_set :@configurations, (configurations = mock)
42
+ assert_equal configurations, Clickhouse.configurations
43
+ end
44
+ end
45
+
46
+ describe ".establish_connection" do
47
+ describe "when valid" do
48
+ before do
49
+ @connection = mock
50
+ @connection.expects(:connect!)
51
+ end
52
+
53
+ it "accepts configuration hashes" do
54
+ config = {"host" => "localhost"}
55
+ Clickhouse::Connection.expects(:new).with(config).returns(@connection)
56
+ Clickhouse.establish_connection config
57
+ end
58
+
59
+ it "accepts configuration names" do
60
+ config = {"host" => "localhost"}
61
+ Clickhouse.instance_variable_set(:@configurations, {"foo" => config})
62
+ Clickhouse::Connection.expects(:new).with(config).returns(@connection)
63
+ Clickhouse.establish_connection "foo"
64
+ end
65
+
66
+ describe "cluster connections" do
67
+ it "creates a connection pool" do
68
+ config = {:urls => %w(localhost:1234 localhost:1235 localhost:1236)}
69
+ Clickhouse::Cluster.expects(:new).with(config).returns(@connection)
70
+ Clickhouse.establish_connection config
71
+ end
72
+ end
73
+ end
74
+
75
+ describe "when invalid" do
76
+ it "denies non-configuration arguments" do
77
+ assert_raises Clickhouse::InvalidConnectionError do
78
+ Clickhouse.establish_connection 123
79
+ end
80
+ assert_raises Clickhouse::InvalidConnectionError do
81
+ Clickhouse.establish_connection true
82
+ end
83
+ assert_raises Clickhouse::InvalidConnectionError do
84
+ Clickhouse.establish_connection "foo"
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ describe ".connection" do
91
+ it "returns its instance variable :@connection" do
92
+ Clickhouse.instance_variable_set :@connection, (connection = mock)
93
+ assert_equal connection, Clickhouse.connection
94
+ end
95
+ end
96
+ end
97
+
98
+ end
99
+ end
@@ -0,0 +1,55 @@
1
+ require_relative "../test_helper"
2
+
3
+ module Unit
4
+ class TestConnection < MiniTest::Test
5
+
6
+ describe Clickhouse::Connection do
7
+ before do
8
+ @connection = Clickhouse::Connection.new
9
+ end
10
+
11
+ describe "included modules" do
12
+ it "includes all Clickhouse::Connection modules" do
13
+ assert_equal true, @connection.class.included_modules.include?(Clickhouse::Connection::Client)
14
+ assert_equal true, @connection.class.included_modules.include?(Clickhouse::Connection::Logger)
15
+ assert_equal true, @connection.class.included_modules.include?(Clickhouse::Connection::Query)
16
+ end
17
+ end
18
+
19
+ describe "#initialize" do
20
+ describe "when not passing a configuration" do
21
+ it "uses a default configuration" do
22
+ assert_equal({
23
+ :scheme => "http",
24
+ :host => "localhost",
25
+ :port => 8123
26
+ }, @connection.instance_variable_get(:@config))
27
+ end
28
+ end
29
+
30
+ describe "when passing a configuration" do
31
+ it "overrides the default configuration" do
32
+ connection = Clickhouse::Connection.new :scheme => "https", "host" => "19.82.8.1"
33
+ assert_equal({
34
+ :scheme => "https",
35
+ :host => "19.82.8.1",
36
+ :port => 8123
37
+ }, connection.instance_variable_get(:@config))
38
+ end
39
+ end
40
+
41
+ describe "when passing a URL" do
42
+ it "derives the scheme, host and port" do
43
+ connection = Clickhouse::Connection.new :url => "https://19.82.8.1:1947"
44
+ assert_equal({
45
+ :scheme => "https",
46
+ :host => "19.82.8.1",
47
+ :port => 1947
48
+ }, connection.instance_variable_get(:@config))
49
+ end
50
+ end
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "../test_helper"
2
+
3
+ module Unit
4
+ class TestUtils < MiniTest::Test
5
+
6
+ describe Clickhouse::Utils do
7
+ describe ".normalize_url" do
8
+ describe "when passing scheme" do
9
+ it "returns the passed url" do
10
+ assert_equal "paul://engel", Clickhouse::Utils.normalize_url("paul://engel")
11
+ end
12
+ end
13
+
14
+ describe "when not passing scheme" do
15
+ it "prepends the default scheme" do
16
+ assert_equal "http://engel", Clickhouse::Utils.normalize_url("engel")
17
+ end
18
+ end
19
+ end
20
+
21
+ describe ".extract_format" do
22
+ describe "when not having a format" do
23
+ it "returns the query and nil as format" do
24
+ assert_equal ["SELECT 1", nil], Clickhouse::Utils.extract_format("SELECT 1")
25
+ end
26
+ end
27
+
28
+ it "strips the query" do
29
+ assert_equal ["SELECT 1", nil], Clickhouse::Utils.extract_format("SELECT 1 ")
30
+ end
31
+
32
+ it "extracts the format from the query" do
33
+ assert_equal ["SELECT 1", "SomeFormat"], Clickhouse::Utils.extract_format("SELECT 1 FORMAT SomeFormat")
34
+ end
35
+ end
36
+ end
37
+
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,326 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ch-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Engel
8
+ - Shiv Bharthur
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2017-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: 1.13.4
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: 1.13.4
28
+ - !ruby/object:Gem::Dependency
29
+ name: faraday
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: pond
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: activesupport
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: 4.1.8
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 4.1.8
70
+ - !ruby/object:Gem::Dependency
71
+ name: sinatra
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: erubis
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :runtime
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: launchy
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ type: :runtime
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ - !ruby/object:Gem::Dependency
113
+ name: thor
114
+ requirement: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ type: :runtime
120
+ prerelease: false
121
+ version_requirements: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rake
128
+ requirement: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ type: :development
134
+ prerelease: false
135
+ version_requirements: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ - !ruby/object:Gem::Dependency
141
+ name: pry
142
+ requirement: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ type: :development
148
+ prerelease: false
149
+ version_requirements: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ - !ruby/object:Gem::Dependency
155
+ name: dotenv
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ - !ruby/object:Gem::Dependency
169
+ name: codeclimate-test-reporter
170
+ requirement: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ type: :development
176
+ prerelease: false
177
+ version_requirements: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ - !ruby/object:Gem::Dependency
183
+ name: simplecov
184
+ requirement: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: '0'
189
+ type: :development
190
+ prerelease: false
191
+ version_requirements: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ - !ruby/object:Gem::Dependency
197
+ name: minitest
198
+ requirement: !ruby/object:Gem::Requirement
199
+ requirements:
200
+ - - ">="
201
+ - !ruby/object:Gem::Version
202
+ version: '0'
203
+ type: :development
204
+ prerelease: false
205
+ version_requirements: !ruby/object:Gem::Requirement
206
+ requirements:
207
+ - - ">="
208
+ - !ruby/object:Gem::Version
209
+ version: '0'
210
+ - !ruby/object:Gem::Dependency
211
+ name: mocha
212
+ requirement: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ type: :development
218
+ prerelease: false
219
+ version_requirements: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ description: A Ruby database driver for ClickHouse (also Clickhouse CLI and web GUI
225
+ included)
226
+ email:
227
+ - pm_engel@icloud.com
228
+ - shiv.bharthur@gmail.com
229
+ executables:
230
+ - clickhouse
231
+ extensions: []
232
+ extra_rdoc_files: []
233
+ files:
234
+ - ".codeclimate.yml"
235
+ - ".gitignore"
236
+ - ".travis.yml"
237
+ - CHANGELOG.md
238
+ - Gemfile
239
+ - MIT-LICENSE
240
+ - README.md
241
+ - Rakefile
242
+ - VERSION
243
+ - bin/clickhouse
244
+ - clickhouse.gemspec
245
+ - lib/clickhouse.rb
246
+ - lib/clickhouse/cli.rb
247
+ - lib/clickhouse/cli/client.rb
248
+ - lib/clickhouse/cli/console.rb
249
+ - lib/clickhouse/cli/server.rb
250
+ - lib/clickhouse/cli/server/assets/css/clickhouse.css
251
+ - lib/clickhouse/cli/server/assets/css/codemirror.css
252
+ - lib/clickhouse/cli/server/assets/css/datatables.css
253
+ - lib/clickhouse/cli/server/assets/css/normalize.css
254
+ - lib/clickhouse/cli/server/assets/css/skeleton.css
255
+ - lib/clickhouse/cli/server/assets/js/clickhouse.js
256
+ - lib/clickhouse/cli/server/assets/js/codemirror.js
257
+ - lib/clickhouse/cli/server/assets/js/datatables.js
258
+ - lib/clickhouse/cli/server/assets/js/disableswipeback.js
259
+ - lib/clickhouse/cli/server/assets/js/jquery.js
260
+ - lib/clickhouse/cli/server/assets/js/sql.js
261
+ - lib/clickhouse/cli/server/views/index.erb
262
+ - lib/clickhouse/cluster.rb
263
+ - lib/clickhouse/connection.rb
264
+ - lib/clickhouse/connection/client.rb
265
+ - lib/clickhouse/connection/logger.rb
266
+ - lib/clickhouse/connection/query.rb
267
+ - lib/clickhouse/connection/query/result_row.rb
268
+ - lib/clickhouse/connection/query/result_set.rb
269
+ - lib/clickhouse/connection/query/table.rb
270
+ - lib/clickhouse/error.rb
271
+ - lib/clickhouse/utils.rb
272
+ - lib/clickhouse/version.rb
273
+ - script/console
274
+ - test/test_helper.rb
275
+ - test/test_helper/coverage.rb
276
+ - test/test_helper/minitest.rb
277
+ - test/test_helper/simple_connection.rb
278
+ - test/unit/connection/query/test_result_row.rb
279
+ - test/unit/connection/query/test_result_set.rb
280
+ - test/unit/connection/query/test_table.rb
281
+ - test/unit/connection/test_client.rb
282
+ - test/unit/connection/test_cluster.rb
283
+ - test/unit/connection/test_logger.rb
284
+ - test/unit/connection/test_query.rb
285
+ - test/unit/test_clickhouse.rb
286
+ - test/unit/test_connection.rb
287
+ - test/unit/test_utils.rb
288
+ homepage: https://github.com/archan937/clickhouse
289
+ licenses:
290
+ - MIT
291
+ metadata: {}
292
+ post_install_message:
293
+ rdoc_options: []
294
+ require_paths:
295
+ - lib
296
+ required_ruby_version: !ruby/object:Gem::Requirement
297
+ requirements:
298
+ - - ">="
299
+ - !ruby/object:Gem::Version
300
+ version: '0'
301
+ required_rubygems_version: !ruby/object:Gem::Requirement
302
+ requirements:
303
+ - - ">="
304
+ - !ruby/object:Gem::Version
305
+ version: '0'
306
+ requirements: []
307
+ rubyforge_project:
308
+ rubygems_version: 2.5.2
309
+ signing_key:
310
+ specification_version: 4
311
+ summary: A Ruby database driver for ClickHouse (also Clickhouse CLI and web GUI included)
312
+ test_files:
313
+ - test/test_helper.rb
314
+ - test/test_helper/coverage.rb
315
+ - test/test_helper/minitest.rb
316
+ - test/test_helper/simple_connection.rb
317
+ - test/unit/connection/query/test_result_row.rb
318
+ - test/unit/connection/query/test_result_set.rb
319
+ - test/unit/connection/query/test_table.rb
320
+ - test/unit/connection/test_client.rb
321
+ - test/unit/connection/test_cluster.rb
322
+ - test/unit/connection/test_logger.rb
323
+ - test/unit/connection/test_query.rb
324
+ - test/unit/test_clickhouse.rb
325
+ - test/unit/test_connection.rb
326
+ - test/unit/test_utils.rb