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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c1ce9f4613cd0dcd9620da942c301d828f2c29fe
4
- data.tar.gz: 813e819830b425a3483d6d859c96d35293576f10
2
+ SHA256:
3
+ metadata.gz: bb0197094ad900501646a07772ec0116aad46f694ac0aebf3917ec54d97646f5
4
+ data.tar.gz: a7039266527540b20084854ddb0fbc939fad47486dc2d9239aff2e2899e87c1f
5
5
  SHA512:
6
- metadata.gz: e0ed42cf6fbb9f1f002fe0f7187e224bc20ad595dede752be19b563566e2afe259e3a4424fc9c8b5421e0af87b0bd1a1478987e3b98fd56ea580c67acfd74520
7
- data.tar.gz: 8947212b75c06e47f4e3e0cdf6d602dff157b6885bc4ead3f8e7e4fc7a74e84e2c77e4608ad544d2467fe8f57473924201411f444cc132944439de1b928deaab
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
@@ -21,7 +21,7 @@ module ActiveHouse
21
21
 
22
22
  def select_all(sql, *bindings)
23
23
  prepared_sql = prepared_statement(sql, *bindings)
24
- connection.query(prepared_sql)
24
+ connection.post_query(prepared_sql)
25
25
  end
26
26
 
27
27
  def select_values(sql, *bindings)
@@ -1,4 +1,5 @@
1
1
  require 'active_model/conversion'
2
+ require 'active_support/core_ext/module/delegation'
2
3
  require 'active_model/naming'
3
4
  require 'plain_model/modeling/base'
4
5
  require 'plain_model/modeling/queryable'
@@ -97,6 +97,14 @@ module ActiveHouse
97
97
  super
98
98
  end
99
99
  end
100
+
101
+ def ==(other)
102
+ other.class == self.class && other._attributes == _attributes
103
+ end
104
+
105
+ protected
106
+
107
+ attr_reader :_attributes
100
108
  end
101
109
  end
102
110
  end
@@ -15,11 +15,11 @@ module ActiveHouse
15
15
 
16
16
  class_methods do
17
17
  def _connection
18
- Thread[name]
18
+ Thread.current[name]
19
19
  end
20
20
 
21
21
  def _connection=(value)
22
- Thread[name] = value
22
+ Thread.current[name] = value
23
23
  end
24
24
 
25
25
  def ensure_connection
@@ -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[:subquery].nil?
12
- query = values[:subquery].is_a?(ActiveHouse::QueryBuilder) ? values[:subquery].to_query : values[:subquery].to_s
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[:subquery] = table_or_subquery.dup
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[:fields].empty?
14
- "SELECT\n#{values[:fields].join(",\n")}"
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 fields: []
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[:fields] = (values[:fields] + formatted_fields).uniq
30
+ values[:select] = (values[:select] + formatted_fields).uniq
31
31
  self
32
32
  end
33
33
  end
@@ -1,3 +1,3 @@
1
1
  module ActiveHouse
2
- VERSION = '0.6.3'.freeze
2
+ VERSION = '0.7.0'.freeze
3
3
  end
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.6.3
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: 2019-08-06 00:00:00.000000000 Z
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
- rubyforge_project:
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