clickhouse 0.1.4 → 0.1.8

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.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +22 -0
  3. data/.travis.yml +0 -2
  4. data/CHANGELOG.md +21 -0
  5. data/README.md +28 -1
  6. data/VERSION +1 -1
  7. data/bin/clickhouse +9 -0
  8. data/clickhouse.gemspec +7 -2
  9. data/lib/clickhouse.rb +7 -2
  10. data/lib/clickhouse/cli.rb +55 -0
  11. data/lib/clickhouse/cli/client.rb +149 -0
  12. data/lib/clickhouse/cli/console.rb +73 -0
  13. data/lib/clickhouse/cli/server.rb +36 -0
  14. data/lib/clickhouse/cli/server/assets/css/clickhouse.css +177 -0
  15. data/lib/clickhouse/cli/server/assets/css/codemirror.css +341 -0
  16. data/lib/clickhouse/cli/server/assets/css/datatables.css +1 -0
  17. data/lib/clickhouse/cli/server/assets/css/normalize.css +427 -0
  18. data/lib/clickhouse/cli/server/assets/css/skeleton.css +418 -0
  19. data/lib/clickhouse/cli/server/assets/js/clickhouse.js +188 -0
  20. data/lib/clickhouse/cli/server/assets/js/codemirror.js +9096 -0
  21. data/lib/clickhouse/cli/server/assets/js/datatables.js +166 -0
  22. data/lib/clickhouse/cli/server/assets/js/disableswipeback.js +97 -0
  23. data/lib/clickhouse/cli/server/assets/js/jquery.js +11015 -0
  24. data/lib/clickhouse/cli/server/assets/js/sql.js +232 -0
  25. data/lib/clickhouse/cli/server/views/index.erb +46 -0
  26. data/lib/clickhouse/cluster.rb +2 -1
  27. data/lib/clickhouse/connection.rb +2 -2
  28. data/lib/clickhouse/connection/client.rb +79 -10
  29. data/lib/clickhouse/connection/query.rb +7 -8
  30. data/lib/clickhouse/connection/query/result_set.rb +2 -0
  31. data/lib/clickhouse/utils.rb +23 -0
  32. data/lib/clickhouse/version.rb +1 -1
  33. data/test/unit/connection/test_client.rb +75 -10
  34. data/test/unit/connection/test_cluster.rb +1 -1
  35. data/test/unit/connection/test_logger.rb +3 -3
  36. data/test/unit/connection/test_query.rb +25 -23
  37. data/test/unit/test_utils.rb +39 -0
  38. metadata +86 -6
@@ -0,0 +1,36 @@
1
+ require "tilt/erubis"
2
+
3
+ module Clickhouse
4
+ class CLI < Thor
5
+ class Server < Sinatra::Base
6
+ include Client
7
+
8
+ set :views, File.expand_path("../server/views", __FILE__)
9
+ set :public_folder, File.expand_path("../server/assets", __FILE__)
10
+
11
+ get "/" do
12
+ erb :index
13
+ end
14
+
15
+ post "/" do
16
+ sql = prettify(params[:sql]).gsub(/\s+;$/, ";")
17
+ alter_history(sql, false)
18
+ begin
19
+ execute(sql) do |result, log|
20
+ content_type :json
21
+ {
22
+ :urls => Clickhouse.connection.pond.available.collect(&:url),
23
+ :history => Readline::HISTORY.to_a.collect(&:strip),
24
+ :names => result.names,
25
+ :data => result.to_a,
26
+ :stats => log.sub("\e[1m\e[36m", "").sub("\e[0m", "").strip
27
+ }.to_json
28
+ end
29
+ rescue Clickhouse::Error => e
30
+ halt 500, e.message
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,177 @@
1
+ @import url('https://fonts.googleapis.com/css?family=Inconsolata|Open+Sans');
2
+
3
+ body {
4
+ font-family: 'Open Sans', sans-serif;
5
+ font-size: 1.2rem;
6
+ }
7
+
8
+ h1, h2, h3, h4, h5, h6 {
9
+ margin-bottom: 1.1rem;
10
+ }
11
+
12
+ h6 {
13
+ font-size: 1.75rem;
14
+ font-weight: 600;
15
+ }
16
+
17
+ .header {
18
+ padding: 5px 17px;
19
+ background: #F3F3F3;
20
+ border-bottom: 1px solid #E0E0E0;
21
+ }
22
+
23
+ .container {
24
+ width: calc(100% - 36px);
25
+ max-width: inherit;
26
+ }
27
+
28
+ .not_connected {
29
+ color: #D74D2F;
30
+ }
31
+
32
+ small {
33
+ font-size: 1.2rem;
34
+ }
35
+
36
+ a {
37
+ text-decoration: none;
38
+ }
39
+
40
+ a:hover {
41
+ text-decoration: underline;
42
+ }
43
+
44
+ form {
45
+ margin-bottom: 7px;
46
+ }
47
+
48
+ textarea {
49
+ opacity: 0;
50
+ }
51
+
52
+ textarea, .CodeMirror {
53
+ margin-bottom: 1.3em;
54
+ width: 100%;
55
+ height: 9.1em;
56
+ display: block;
57
+ font-family: 'Inconsolata';
58
+ font-size: 1.2rem;
59
+ font-weight: 600;
60
+ line-height: 1.75rem;
61
+ letter-spacing: 0;
62
+ border: 1px solid #DDD;
63
+ }
64
+
65
+ input[type="submit"], a.download {
66
+ height: 30px;
67
+ margin-right: 4px;
68
+ padding: 0 17px 0 20px;
69
+ color: white;
70
+ font-size: 10px;
71
+ line-height: 28px;
72
+ letter-spacing: .05rem;
73
+ border-radius: 0;
74
+ }
75
+
76
+ input[type="submit"] {
77
+ background: #D74D2F;
78
+ border-color: #D74D2F;
79
+ }
80
+
81
+ a.download {
82
+ background: #999;
83
+ border-color: #999;
84
+ }
85
+
86
+ input[type="submit"]:hover, input[type="submit"]:focus {
87
+ color: white;
88
+ border-color: #B30015;
89
+ }
90
+
91
+ a.download:hover, a.download:focus {
92
+ color: white;
93
+ text-decoration: none;
94
+ }
95
+
96
+ input[disabled="disabled"],a[disabled="disabled"] {
97
+ color: #F9F9F9;
98
+ cursor: default !important;
99
+ background: #E4E4E4;
100
+ border-color: #E7E7E7 !important;
101
+ }
102
+
103
+ #stats {
104
+ padding-left: 1.5rem;
105
+ }
106
+
107
+ #result_wrapper {
108
+ margin-bottom: 10px;
109
+ padding-top: 18px;
110
+ overflow-x: auto;
111
+ border-top: 1px solid #DDD;
112
+ }
113
+
114
+ #result_filter {
115
+ float: left;
116
+ }
117
+
118
+ #result_filter label {
119
+ padding-left: 1px;
120
+ font-family: 'Helvetica Neue', 'Arial';
121
+ font-weight: bold;
122
+ }
123
+
124
+ #result_filter input[type="search"] {
125
+ width: 300px;
126
+ height: 28px;
127
+ margin-left: 12px;
128
+ margin-bottom: 12px;
129
+ padding: 6px 7px;
130
+ font-weight: normal;
131
+ border-radius: 0;
132
+ }
133
+
134
+ #result_filter input[type="search"]:focus {
135
+ border-color: #999;
136
+ }
137
+
138
+ #result {
139
+ width: 100% !important;
140
+ margin-bottom: 15px;
141
+ font-family: 'Helvetica Neue', 'Arial';
142
+ font-size: 1.25rem;
143
+ }
144
+
145
+ table#result {
146
+ border: 0;
147
+ border-top: 2px solid #111;
148
+ border-left: 1px solid #DDD;
149
+ }
150
+
151
+ #result th, #result td {
152
+ padding: 4px 8px;
153
+ border: 0;
154
+ border-right: 1px solid #DDD;
155
+ border-bottom: 1px solid #DDD;
156
+ }
157
+
158
+ #result th {
159
+ background: #EEE;
160
+ }
161
+
162
+ #result td {
163
+ white-space: nowrap;
164
+ }
165
+
166
+ #result td.odd {
167
+ background: #DDD;
168
+ }
169
+
170
+ #result td.even {
171
+ background: #FFF;
172
+ }
173
+
174
+ #result_info {
175
+ height: 3px;
176
+ display: none;
177
+ }
@@ -0,0 +1,341 @@
1
+ /* BASICS */
2
+
3
+ .CodeMirror {
4
+ /* Set height, width, borders, and global font properties here */
5
+ font-family: monospace;
6
+ height: 300px;
7
+ color: black;
8
+ }
9
+
10
+ /* PADDING */
11
+
12
+ .CodeMirror-lines {
13
+ padding: 4px 0; /* Vertical padding around content */
14
+ }
15
+ .CodeMirror pre {
16
+ padding: 0 4px; /* Horizontal padding of content */
17
+ }
18
+
19
+ .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
20
+ background-color: white; /* The little square between H and V scrollbars */
21
+ }
22
+
23
+ /* GUTTER */
24
+
25
+ .CodeMirror-gutters {
26
+ border-right: 1px solid #ddd;
27
+ background-color: #f7f7f7;
28
+ white-space: nowrap;
29
+ }
30
+ .CodeMirror-linenumbers {}
31
+ .CodeMirror-linenumber {
32
+ padding: 0 3px 0 5px;
33
+ min-width: 20px;
34
+ text-align: right;
35
+ color: #999;
36
+ white-space: nowrap;
37
+ }
38
+
39
+ .CodeMirror-guttermarker { color: black; }
40
+ .CodeMirror-guttermarker-subtle { color: #999; }
41
+
42
+ /* CURSOR */
43
+
44
+ .CodeMirror-cursor {
45
+ border-left: 1px solid black;
46
+ border-right: none;
47
+ width: 0;
48
+ }
49
+ /* Shown when moving in bi-directional text */
50
+ .CodeMirror div.CodeMirror-secondarycursor {
51
+ border-left: 1px solid silver;
52
+ }
53
+ .cm-fat-cursor .CodeMirror-cursor {
54
+ width: auto;
55
+ border: 0 !important;
56
+ background: #7e7;
57
+ }
58
+ .cm-fat-cursor div.CodeMirror-cursors {
59
+ z-index: 1;
60
+ }
61
+
62
+ .cm-animate-fat-cursor {
63
+ width: auto;
64
+ border: 0;
65
+ -webkit-animation: blink 1.06s steps(1) infinite;
66
+ -moz-animation: blink 1.06s steps(1) infinite;
67
+ animation: blink 1.06s steps(1) infinite;
68
+ background-color: #7e7;
69
+ }
70
+ @-moz-keyframes blink {
71
+ 0% {}
72
+ 50% { background-color: transparent; }
73
+ 100% {}
74
+ }
75
+ @-webkit-keyframes blink {
76
+ 0% {}
77
+ 50% { background-color: transparent; }
78
+ 100% {}
79
+ }
80
+ @keyframes blink {
81
+ 0% {}
82
+ 50% { background-color: transparent; }
83
+ 100% {}
84
+ }
85
+
86
+ /* Can style cursor different in overwrite (non-insert) mode */
87
+ .CodeMirror-overwrite .CodeMirror-cursor {}
88
+
89
+ .cm-tab { display: inline-block; text-decoration: inherit; }
90
+
91
+ .CodeMirror-rulers {
92
+ position: absolute;
93
+ left: 0; right: 0; top: -50px; bottom: -20px;
94
+ overflow: hidden;
95
+ }
96
+ .CodeMirror-ruler {
97
+ border-left: 1px solid #ccc;
98
+ top: 0; bottom: 0;
99
+ position: absolute;
100
+ }
101
+
102
+ /* DEFAULT THEME */
103
+
104
+ .cm-s-default .cm-header {color: blue;}
105
+ .cm-s-default .cm-quote {color: #090;}
106
+ .cm-negative {color: #d44;}
107
+ .cm-positive {color: #292;}
108
+ .cm-header, .cm-strong {font-weight: bold;}
109
+ .cm-em {font-style: italic;}
110
+ .cm-link {text-decoration: underline;}
111
+ .cm-strikethrough {text-decoration: line-through;}
112
+
113
+ .cm-s-default .cm-keyword {color: #708;}
114
+ .cm-s-default .cm-atom {color: #219;}
115
+ .cm-s-default .cm-number {color: #164;}
116
+ .cm-s-default .cm-def {color: #00f;}
117
+ .cm-s-default .cm-variable,
118
+ .cm-s-default .cm-punctuation,
119
+ .cm-s-default .cm-property,
120
+ .cm-s-default .cm-operator {}
121
+ .cm-s-default .cm-variable-2 {color: #05a;}
122
+ .cm-s-default .cm-variable-3 {color: #085;}
123
+ .cm-s-default .cm-comment {color: #a50;}
124
+ .cm-s-default .cm-string {color: #a11;}
125
+ .cm-s-default .cm-string-2 {color: #f50;}
126
+ .cm-s-default .cm-meta {color: #555;}
127
+ .cm-s-default .cm-qualifier {color: #555;}
128
+ .cm-s-default .cm-builtin {color: #30a;}
129
+ .cm-s-default .cm-bracket {color: #997;}
130
+ .cm-s-default .cm-tag {color: #170;}
131
+ .cm-s-default .cm-attribute {color: #00c;}
132
+ .cm-s-default .cm-hr {color: #999;}
133
+ .cm-s-default .cm-link {color: #00c;}
134
+
135
+ .cm-s-default .cm-error {color: #f00;}
136
+ .cm-invalidchar {color: #f00;}
137
+
138
+ .CodeMirror-composing { border-bottom: 2px solid; }
139
+
140
+ /* Default styles for common addons */
141
+
142
+ div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
143
+ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
144
+ .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
145
+ .CodeMirror-activeline-background {background: #e8f2ff;}
146
+
147
+ /* STOP */
148
+
149
+ /* The rest of this file contains styles related to the mechanics of
150
+ the editor. You probably shouldn't touch them. */
151
+
152
+ .CodeMirror {
153
+ position: relative;
154
+ overflow: hidden;
155
+ background: white;
156
+ }
157
+
158
+ .CodeMirror-scroll {
159
+ overflow: scroll !important; /* Things will break if this is overridden */
160
+ /* 30px is the magic margin used to hide the element's real scrollbars */
161
+ /* See overflow: hidden in .CodeMirror */
162
+ margin-bottom: -30px; margin-right: -30px;
163
+ padding-bottom: 30px;
164
+ height: 100%;
165
+ outline: none; /* Prevent dragging from highlighting the element */
166
+ position: relative;
167
+ }
168
+ .CodeMirror-sizer {
169
+ position: relative;
170
+ border-right: 30px solid transparent;
171
+ }
172
+
173
+ /* The fake, visible scrollbars. Used to force redraw during scrolling
174
+ before actual scrolling happens, thus preventing shaking and
175
+ flickering artifacts. */
176
+ .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
177
+ position: absolute;
178
+ z-index: 6;
179
+ display: none;
180
+ }
181
+ .CodeMirror-vscrollbar {
182
+ right: 0; top: 0;
183
+ overflow-x: hidden;
184
+ overflow-y: scroll;
185
+ }
186
+ .CodeMirror-hscrollbar {
187
+ bottom: 0; left: 0;
188
+ overflow-y: hidden;
189
+ overflow-x: scroll;
190
+ }
191
+ .CodeMirror-scrollbar-filler {
192
+ right: 0; bottom: 0;
193
+ }
194
+ .CodeMirror-gutter-filler {
195
+ left: 0; bottom: 0;
196
+ }
197
+
198
+ .CodeMirror-gutters {
199
+ position: absolute; left: 0; top: 0;
200
+ min-height: 100%;
201
+ z-index: 3;
202
+ }
203
+ .CodeMirror-gutter {
204
+ white-space: normal;
205
+ height: 100%;
206
+ display: inline-block;
207
+ vertical-align: top;
208
+ margin-bottom: -30px;
209
+ }
210
+ .CodeMirror-gutter-wrapper {
211
+ position: absolute;
212
+ z-index: 4;
213
+ background: none !important;
214
+ border: none !important;
215
+ }
216
+ .CodeMirror-gutter-background {
217
+ position: absolute;
218
+ top: 0; bottom: 0;
219
+ z-index: 4;
220
+ }
221
+ .CodeMirror-gutter-elt {
222
+ position: absolute;
223
+ cursor: default;
224
+ z-index: 4;
225
+ }
226
+ .CodeMirror-gutter-wrapper {
227
+ -webkit-user-select: none;
228
+ -moz-user-select: none;
229
+ user-select: none;
230
+ }
231
+
232
+ .CodeMirror-lines {
233
+ cursor: text;
234
+ min-height: 1px; /* prevents collapsing before first draw */
235
+ }
236
+ .CodeMirror pre {
237
+ /* Reset some styles that the rest of the page might have set */
238
+ -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
239
+ border-width: 0;
240
+ background: transparent;
241
+ font-family: inherit;
242
+ font-size: inherit;
243
+ margin: 0;
244
+ white-space: pre;
245
+ word-wrap: normal;
246
+ line-height: inherit;
247
+ color: inherit;
248
+ z-index: 2;
249
+ position: relative;
250
+ overflow: visible;
251
+ -webkit-tap-highlight-color: transparent;
252
+ -webkit-font-variant-ligatures: none;
253
+ font-variant-ligatures: none;
254
+ }
255
+ .CodeMirror-wrap pre {
256
+ word-wrap: break-word;
257
+ white-space: pre-wrap;
258
+ word-break: normal;
259
+ }
260
+
261
+ .CodeMirror-linebackground {
262
+ position: absolute;
263
+ left: 0; right: 0; top: 0; bottom: 0;
264
+ z-index: 0;
265
+ }
266
+
267
+ .CodeMirror-linewidget {
268
+ position: relative;
269
+ z-index: 2;
270
+ overflow: auto;
271
+ }
272
+
273
+ .CodeMirror-widget {}
274
+
275
+ .CodeMirror-code {
276
+ outline: none;
277
+ }
278
+
279
+ /* Force content-box sizing for the elements where we expect it */
280
+ .CodeMirror-scroll,
281
+ .CodeMirror-sizer,
282
+ .CodeMirror-gutter,
283
+ .CodeMirror-gutters,
284
+ .CodeMirror-linenumber {
285
+ -moz-box-sizing: content-box;
286
+ box-sizing: content-box;
287
+ }
288
+
289
+ .CodeMirror-measure {
290
+ position: absolute;
291
+ width: 100%;
292
+ height: 0;
293
+ overflow: hidden;
294
+ visibility: hidden;
295
+ }
296
+
297
+ .CodeMirror-cursor {
298
+ position: absolute;
299
+ pointer-events: none;
300
+ }
301
+ .CodeMirror-measure pre { position: static; }
302
+
303
+ div.CodeMirror-cursors {
304
+ visibility: hidden;
305
+ position: relative;
306
+ z-index: 3;
307
+ }
308
+ div.CodeMirror-dragcursors {
309
+ visibility: visible;
310
+ }
311
+
312
+ .CodeMirror-focused div.CodeMirror-cursors {
313
+ visibility: visible;
314
+ }
315
+
316
+ .CodeMirror-selected { background: #d9d9d9; }
317
+ .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
318
+ .CodeMirror-crosshair { cursor: crosshair; }
319
+ .CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
320
+ .CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
321
+
322
+ .cm-searching {
323
+ background: #ffa;
324
+ background: rgba(255, 255, 0, .4);
325
+ }
326
+
327
+ /* Used to force a border model for a node */
328
+ .cm-force-border { padding-right: .1px; }
329
+
330
+ @media print {
331
+ /* Hide the cursor when printing */
332
+ .CodeMirror div.CodeMirror-cursors {
333
+ visibility: hidden;
334
+ }
335
+ }
336
+
337
+ /* See issue #2901 */
338
+ .cm-tab-wrap-hack:after { content: ''; }
339
+
340
+ /* Help users use markselection to safely style text background */
341
+ span.CodeMirror-selectedtext { background: none; }