active_house 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/tests.yml +27 -0
- data/Gemfile +6 -0
- data/active_house.gemspec +0 -4
- data/bin/setup +0 -0
- data/lib/active_house/connection.rb +1 -1
- data/lib/active_house/model.rb +1 -0
- data/lib/active_house/modeling/attributes.rb +8 -0
- data/lib/active_house/modeling/connection.rb +2 -2
- data/lib/active_house/query_builder.rb +2 -2
- data/lib/active_house/querying/except.rb +27 -0
- data/lib/active_house/querying/from.rb +3 -3
- data/lib/active_house/querying/select.rb +4 -4
- data/lib/active_house/version.rb +1 -1
- data/lib/active_house.rb +3 -0
- data/lib/clickhouse/connection/post_query.rb +47 -0
- metadata +6 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bb0197094ad900501646a07772ec0116aad46f694ac0aebf3917ec54d97646f5
|
4
|
+
data.tar.gz: a7039266527540b20084854ddb0fbc939fad47486dc2d9239aff2e2899e87c1f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4eb7b21237f15550fdff809ec3aa188d9c3e0f0ef46b105ba949172f77c094974785c44f81f225dbd5d8b70cd05faad3c5ef985ac2ce9d155bbe45fa6328c91d
|
7
|
+
data.tar.gz: e1a4bc99777aca92c9d28998e4d2098e3c754a7c7c7a61ae06f4f0430ec2a07d4e00ce01b9d3136601d5ba8f1974ee5a27512102e18ee45dded44ae364d24faa
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Tests
|
2
|
+
on:
|
3
|
+
pull_request:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
test:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.5', '2.6', '2.7' ]
|
14
|
+
rails: [ '~> 5.0', '~> 6.0' ]
|
15
|
+
name: Tests with Ruby ${{ matrix.ruby }} Activemodel/Activesupport ${{ matrix.rails }}
|
16
|
+
env:
|
17
|
+
RAILS_VERSION: ${{ matrix.rails }}
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- uses: actions/setup-ruby@v1
|
21
|
+
with:
|
22
|
+
ruby-version: ${{ matrix.ruby }}
|
23
|
+
- name: Run tests
|
24
|
+
run: |
|
25
|
+
gem install bundler
|
26
|
+
bundle install
|
27
|
+
bundle exec rake
|
data/Gemfile
CHANGED
@@ -5,6 +5,12 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
|
|
5
5
|
# Specify your gem's dependencies in active_house.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
+
gem 'activemodel', ENV['RAILS_VERSION'], require: false
|
9
|
+
gem 'activesupport', ENV['RAILS_VERSION'], require: false
|
10
|
+
|
8
11
|
group :test do
|
12
|
+
gem 'minitest', '~> 5.0', require: false
|
13
|
+
gem 'rake', '~> 10.0', require: false
|
9
14
|
gem 'rubocop', '0.58.1', require: false
|
15
|
+
gem 'webmock', require: false
|
10
16
|
end
|
data/active_house.gemspec
CHANGED
@@ -27,8 +27,4 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_dependency 'clickhouse', '~> 0.1.10'
|
28
28
|
spec.add_dependency 'kaminari-core', '~> 1.1'
|
29
29
|
spec.add_dependency 'plain_model', '~> 0.2'
|
30
|
-
|
31
|
-
spec.add_development_dependency 'bundler', '~> 1.16'
|
32
|
-
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
-
spec.add_development_dependency 'rake', '~> 10.0'
|
34
30
|
end
|
data/bin/setup
CHANGED
File without changes
|
data/lib/active_house/model.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'plain_model/querying/base'
|
2
|
-
require 'plain_model/querying/except'
|
3
2
|
require 'plain_model/querying/with_model'
|
4
3
|
require_relative 'querying/select'
|
5
4
|
require_relative 'querying/from'
|
@@ -12,12 +11,12 @@ require_relative 'querying/union'
|
|
12
11
|
require_relative 'querying/array_join'
|
13
12
|
require_relative 'querying/page'
|
14
13
|
require_relative 'querying/scope'
|
14
|
+
require_relative 'querying/except'
|
15
15
|
require_relative 'querying/collect'
|
16
16
|
|
17
17
|
module ActiveHouse
|
18
18
|
class QueryBuilder
|
19
19
|
include PlainModel::Querying::Base
|
20
|
-
include PlainModel::Querying::Except
|
21
20
|
include PlainModel::Querying::WithModel
|
22
21
|
|
23
22
|
include ActiveHouse::Querying::Select
|
@@ -31,6 +30,7 @@ module ActiveHouse
|
|
31
30
|
include ActiveHouse::Querying::ArrayJoin
|
32
31
|
include ActiveHouse::Querying::Scope
|
33
32
|
include ActiveHouse::Querying::Page
|
33
|
+
include ActiveHouse::Querying::Except
|
34
34
|
include ActiveHouse::Querying::Collect
|
35
35
|
|
36
36
|
# allows using query without model_class
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module ActiveHouse
|
6
|
+
module Querying
|
7
|
+
module Except
|
8
|
+
extend ActiveSupport::Concern
|
9
|
+
|
10
|
+
# Chain method
|
11
|
+
# @param keys [Array<Symbol>] values keys that you want to exclude from query
|
12
|
+
# @return new instance with applied changes
|
13
|
+
def except(*keys)
|
14
|
+
dup.except!(*keys)
|
15
|
+
end
|
16
|
+
|
17
|
+
# Chain method
|
18
|
+
# @param keys [Array<Symbol>] values keys that you want to exclude from query
|
19
|
+
# @return new instance with applied changes
|
20
|
+
def except!(*keys)
|
21
|
+
values.merge! initial_values.slice(*keys)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -8,8 +8,8 @@ module ActiveHouse
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def from_subquery
|
11
|
-
return model_class._table_name if values[:
|
12
|
-
query = values[:
|
11
|
+
return model_class._table_name if values[:from].nil?
|
12
|
+
query = values[:from].is_a?(ActiveHouse::QueryBuilder) ? values[:from].to_query : values[:from].to_s
|
13
13
|
"( #{query} )"
|
14
14
|
end
|
15
15
|
|
@@ -18,7 +18,7 @@ module ActiveHouse
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def from!(table_or_subquery)
|
21
|
-
values[:
|
21
|
+
values[:from] = table_or_subquery.dup
|
22
22
|
self
|
23
23
|
end
|
24
24
|
|
@@ -10,15 +10,15 @@ module ActiveHouse
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build_select_query_part
|
13
|
-
if !values[:
|
14
|
-
"SELECT\n#{values[:
|
13
|
+
if !values[:select].empty?
|
14
|
+
"SELECT\n#{values[:select].join(",\n")}"
|
15
15
|
else
|
16
16
|
'SELECT *'
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def initial_values
|
21
|
-
super.merge
|
21
|
+
super.merge select: []
|
22
22
|
end
|
23
23
|
|
24
24
|
def select(*fields)
|
@@ -27,7 +27,7 @@ module ActiveHouse
|
|
27
27
|
|
28
28
|
def select!(*fields)
|
29
29
|
formatted_fields = ActiveHouse::PreparedStatement.format_fields(model_class, fields)
|
30
|
-
values[:
|
30
|
+
values[:select] = (values[:select] + formatted_fields).uniq
|
31
31
|
self
|
32
32
|
end
|
33
33
|
end
|
data/lib/active_house/version.rb
CHANGED
data/lib/active_house.rb
CHANGED
@@ -3,6 +3,9 @@ require 'active_house/configuration'
|
|
3
3
|
require 'active_house/model'
|
4
4
|
require 'active_house/query_builder'
|
5
5
|
|
6
|
+
require 'clickhouse/connection/post_query'
|
7
|
+
Clickhouse::Connection.include Clickhouse::Connection::PostQuery
|
8
|
+
|
6
9
|
module ActiveHouse
|
7
10
|
def self.configure
|
8
11
|
yield configuration
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Clickhouse
|
2
|
+
class Connection
|
3
|
+
# By default Clickhouse uses GET request for query, but it has limitation for length on server side.
|
4
|
+
# So we will allow to use POST request with query in a body.
|
5
|
+
module PostQuery
|
6
|
+
|
7
|
+
def post_query(query)
|
8
|
+
query = Utils.extract_format(query)[0]
|
9
|
+
query += ' FORMAT JSONCompact'
|
10
|
+
parse_data post(nil, query)
|
11
|
+
end
|
12
|
+
|
13
|
+
def select_rows(options)
|
14
|
+
post_query to_select_query(options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def request(method, query, body = nil)
|
18
|
+
raise ArgumentError, 'when query is omitted body must be passed' if query.nil? && body.nil?
|
19
|
+
|
20
|
+
connect!
|
21
|
+
body = body.strip unless body.nil?
|
22
|
+
query = query.strip unless query.nil?
|
23
|
+
|
24
|
+
start = Time.now
|
25
|
+
|
26
|
+
headers = { 'Content-Type' => 'text/plain' }
|
27
|
+
response = client.send(method, path(query), body, headers)
|
28
|
+
status = response.status
|
29
|
+
duration = Time.now - start
|
30
|
+
if query.nil?
|
31
|
+
query, format = Utils.extract_format(body)
|
32
|
+
else
|
33
|
+
query, format = Utils.extract_format(query)
|
34
|
+
end
|
35
|
+
response = parse_body(format, response.body)
|
36
|
+
stats = parse_stats(response)
|
37
|
+
|
38
|
+
write_log duration, query, stats
|
39
|
+
raise QueryError, "Got status #{status} (expected 200): #{response}" unless status == 200
|
40
|
+
response
|
41
|
+
rescue Faraday::Error => e
|
42
|
+
raise ConnectionError, e.message
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_house
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Denis Talakevich
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -80,48 +80,6 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.2'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: bundler
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '1.16'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '1.16'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: minitest
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '5.0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '5.0'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: rake
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '10.0'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '10.0'
|
125
83
|
description: ORM and Query DSL for ClickHouse
|
126
84
|
email:
|
127
85
|
- senid231@gmail.com
|
@@ -129,6 +87,7 @@ executables: []
|
|
129
87
|
extensions: []
|
130
88
|
extra_rdoc_files: []
|
131
89
|
files:
|
90
|
+
- ".github/workflows/tests.yml"
|
132
91
|
- ".gitignore"
|
133
92
|
- ".rubocop.yml"
|
134
93
|
- ".travis.yml"
|
@@ -154,6 +113,7 @@ files:
|
|
154
113
|
- lib/active_house/query_builder.rb
|
155
114
|
- lib/active_house/querying/array_join.rb
|
156
115
|
- lib/active_house/querying/collect.rb
|
116
|
+
- lib/active_house/querying/except.rb
|
157
117
|
- lib/active_house/querying/from.rb
|
158
118
|
- lib/active_house/querying/group_by.rb
|
159
119
|
- lib/active_house/querying/having.rb
|
@@ -165,6 +125,7 @@ files:
|
|
165
125
|
- lib/active_house/querying/union.rb
|
166
126
|
- lib/active_house/querying/where.rb
|
167
127
|
- lib/active_house/version.rb
|
128
|
+
- lib/clickhouse/connection/post_query.rb
|
168
129
|
homepage: https://github.com/senid231/active_house
|
169
130
|
licenses:
|
170
131
|
- MIT
|
@@ -184,8 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
145
|
- !ruby/object:Gem::Version
|
185
146
|
version: '0'
|
186
147
|
requirements: []
|
187
|
-
|
188
|
-
rubygems_version: 2.4.8
|
148
|
+
rubygems_version: 3.0.8
|
189
149
|
signing_key:
|
190
150
|
specification_version: 4
|
191
151
|
summary: ORM and Query DSL for ClickHouse
|