click_house 1.2.4 → 1.2.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +45 -3
- data/lib/click_house/extend/connection_inserting.rb +5 -0
- data/lib/click_house/type/base_type.rb +2 -2
- data/lib/click_house/type/nullable_type.rb +2 -2
- data/lib/click_house/type/undefined_type.rb +1 -1
- data/lib/click_house/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 700d57a764315e709b8e78f10a5765801baa2b491aeb4aad6b6cc6c2016f8c74
|
4
|
+
data.tar.gz: 34f61608fd6b67fed90f9ec1d84db1677abdeda86f3c8751fb124457f25274e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bff6c7f9bda496860ee38038bde526f706f7f6a1c1be8be0800806c70c24de15764d090e579c4dafe0bf3e86eca18acfce4a3c96542b5e89756182b8711f8aaf
|
7
|
+
data.tar.gz: 5cd4d79cb422ea0feb9171b2e1ca5eb824d50fabdd718e2789c65e1ce75bcefedd60c479a0a46a9488a0c6ac8f352e25caa07e2c417c8ae79c351c2b121ffd3b
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -38,6 +38,9 @@ Yandex uses HTTP interface for working from Java and Perl, Python and Go as well
|
|
38
38
|
* [Type casting](#type-casting)
|
39
39
|
* [Using with a connection pool](#using-with-a-connection-pool)
|
40
40
|
* [Using with Rails](#using-with-rails)
|
41
|
+
* [Using with ActiveRecord](#using-with-activerecord)
|
42
|
+
* [Using with RSpec](#using-with-rspec)
|
43
|
+
* [Development](#development)
|
41
44
|
|
42
45
|
## Configuration
|
43
46
|
|
@@ -459,18 +462,57 @@ class CreateAdvertVisits < ActiveRecord::Migration[6.0]
|
|
459
462
|
end
|
460
463
|
```
|
461
464
|
|
465
|
+
## Using with ActiveRecord
|
466
|
+
|
462
467
|
if you use `ActiveRecord`, you can use the ORM query builder by using fake models
|
468
|
+
(empty tables must be present in the SQL database `create_table :visits`)
|
469
|
+
|
470
|
+
```ruby
|
471
|
+
class ClickHouseRecord < ActiveRecord::Base
|
472
|
+
self.abstract_class = true
|
473
|
+
|
474
|
+
class << self
|
475
|
+
def agent
|
476
|
+
ClickHouse.connection
|
477
|
+
end
|
478
|
+
|
479
|
+
def insert(*argv, &block)
|
480
|
+
agent.insert(table_name, *argv, &block)
|
481
|
+
end
|
482
|
+
|
483
|
+
def select_one
|
484
|
+
agent.select_one(current_scope.to_sql)
|
485
|
+
end
|
486
|
+
|
487
|
+
def select_value
|
488
|
+
agent.select_value(current_scope.to_sql)
|
489
|
+
end
|
490
|
+
|
491
|
+
def select_all
|
492
|
+
agent.select_all(current_scope.to_sql)
|
493
|
+
end
|
494
|
+
end
|
495
|
+
end
|
496
|
+
````
|
463
497
|
|
464
498
|
````ruby
|
465
499
|
# FAKE MODEL FOR ClickHouse
|
466
|
-
class Visit <
|
500
|
+
class Visit < ClickHouseRecord
|
467
501
|
scope :with_os, -> { where.not(os_family_id: nil) }
|
468
502
|
end
|
469
503
|
|
470
|
-
|
471
|
-
|
504
|
+
Visit.with_os.select('COUNT(*) as counter').group(:ipv4).select_all
|
505
|
+
#=> [{ 'ipv4' => 1455869, 'counter' => 104 }]
|
506
|
+
|
507
|
+
Visit.with_os.select('COUNT(*)').select_value
|
508
|
+
#=> 20_345_678
|
509
|
+
|
510
|
+
Visit.where(user_id: 1).select_one
|
511
|
+
#=> { 'ipv4' => 1455869, 'user_id' => 1 }
|
472
512
|
````
|
473
513
|
|
514
|
+
## Using with RSpec
|
515
|
+
|
474
516
|
You can clear the data table before each test with RSpec
|
475
517
|
|
476
518
|
```ruby
|
@@ -3,6 +3,9 @@
|
|
3
3
|
module ClickHouse
|
4
4
|
module Extend
|
5
5
|
module ConnectionInserting
|
6
|
+
EMPTY_INSERT = true
|
7
|
+
|
8
|
+
# @return [Boolean]
|
6
9
|
def insert(table, columns: [], values: [])
|
7
10
|
yield(values) if block_given?
|
8
11
|
|
@@ -12,6 +15,8 @@ module ClickHouse
|
|
12
15
|
values.map { |value_row| columns.zip(value_row).to_h.to_json }
|
13
16
|
end
|
14
17
|
|
18
|
+
return EMPTY_INSERT if values.empty?
|
19
|
+
|
15
20
|
execute("INSERT INTO #{table} FORMAT JSONEachRow", body.join("\n")).success?
|
16
21
|
end
|
17
22
|
end
|
data/lib/click_house/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: click_house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aliaksandr Shylau
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|