clickhouse-activerecord 0.5.12 → 0.5.14
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/lib/active_record/connection_adapters/clickhouse/oid/array.rb +36 -0
- data/lib/active_record/connection_adapters/clickhouse/schema_creation.rb +5 -1
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +27 -15
- data/lib/clickhouse-activerecord/railtie.rb +6 -0
- data/lib/clickhouse-activerecord/version.rb +1 -1
- data/lib/clickhouse-activerecord.rb +5 -1
- data/lib/core_extensions/active_record/relation.rb +15 -0
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ff54c1e4a5da2543e1a64ad8002822bf82ba5d3b6f7f74f00f1cb0ce23679dd
|
4
|
+
data.tar.gz: 61158e185f4617e88701d2a9b1d261ddf7b4f9c7617454e66a899d55900a34a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d690a0cf443ce6e1b3f90e0443263e27b44be546fd080c11c8aa0278d6f630360371057880e667d4f5f76e31ac9bccf1b71fdfffeda09aa7d4d9a49af786f79
|
7
|
+
data.tar.gz: f0f96caa0371b8206cee957e38b9f24993549eaa2dcc03265d4b398e051a0a9ebe32a7262c949bf4510dda3f843d8e9e2bb2437cc364dd9bf06f5a622e085530
|
@@ -23,6 +23,42 @@ module ActiveRecord
|
|
23
23
|
@subtype
|
24
24
|
end
|
25
25
|
|
26
|
+
def deserialize(value)
|
27
|
+
if value.is_a?(::Array)
|
28
|
+
value.map { |item| deserialize(item) }
|
29
|
+
else
|
30
|
+
return value if value.nil?
|
31
|
+
case @subtype
|
32
|
+
when :integer
|
33
|
+
value.to_i
|
34
|
+
when :datetime
|
35
|
+
::DateTime.parse(value)
|
36
|
+
when :date
|
37
|
+
::Date.parse(value)
|
38
|
+
else
|
39
|
+
super
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def serialize(value)
|
45
|
+
if value.is_a?(::Array)
|
46
|
+
value.map { |item| serialize(item) }
|
47
|
+
else
|
48
|
+
return value if value.nil?
|
49
|
+
case @subtype
|
50
|
+
when :integer
|
51
|
+
value.to_i
|
52
|
+
when :datetime
|
53
|
+
DateTime.new.serialize(value)
|
54
|
+
when :date
|
55
|
+
Date.new.serialize(value)
|
56
|
+
else
|
57
|
+
super
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
26
62
|
end
|
27
63
|
end
|
28
64
|
end
|
@@ -125,7 +125,11 @@ module ActiveRecord
|
|
125
125
|
end
|
126
126
|
|
127
127
|
def current_database
|
128
|
-
ActiveRecord::
|
128
|
+
if ActiveRecord::version >= Gem::Version.new('6')
|
129
|
+
ActiveRecord::Base.connection_db_config.database
|
130
|
+
else
|
131
|
+
ActiveRecord::Base.connection_config[:database]
|
132
|
+
end
|
129
133
|
end
|
130
134
|
end
|
131
135
|
end
|
@@ -11,6 +11,7 @@ require 'active_record/connection_adapters/clickhouse/schema_definitions'
|
|
11
11
|
require 'active_record/connection_adapters/clickhouse/schema_creation'
|
12
12
|
require 'active_record/connection_adapters/clickhouse/schema_statements'
|
13
13
|
require 'net/http'
|
14
|
+
require 'openssl'
|
14
15
|
|
15
16
|
module ActiveRecord
|
16
17
|
class Base
|
@@ -47,19 +48,6 @@ module ActiveRecord
|
|
47
48
|
end
|
48
49
|
end
|
49
50
|
|
50
|
-
module ClickhouseRelationReverseOrder
|
51
|
-
def reverse_order!
|
52
|
-
return super unless connection.is_a?(ConnectionAdapters::ClickhouseAdapter)
|
53
|
-
|
54
|
-
orders = order_values.uniq.compact_blank
|
55
|
-
return super unless orders.empty? && !primary_key
|
56
|
-
|
57
|
-
self.order_values = %w(date created_at).select {|c| column_names.include?(c) }.map{|c| arel_attribute(c).desc }
|
58
|
-
self
|
59
|
-
end
|
60
|
-
end
|
61
|
-
Relation.prepend(ClickhouseRelationReverseOrder)
|
62
|
-
|
63
51
|
module TypeCaster
|
64
52
|
class Map
|
65
53
|
def is_view
|
@@ -73,7 +61,7 @@ module ActiveRecord
|
|
73
61
|
end
|
74
62
|
|
75
63
|
module ModelSchema
|
76
|
-
|
64
|
+
module ClassMethods
|
77
65
|
def is_view
|
78
66
|
@is_view || false
|
79
67
|
end
|
@@ -224,6 +212,15 @@ module ActiveRecord
|
|
224
212
|
end
|
225
213
|
end
|
226
214
|
|
215
|
+
def _quote(value)
|
216
|
+
case value
|
217
|
+
when Array
|
218
|
+
'[' + value.map { |v| _quote(v) }.join(', ') + ']'
|
219
|
+
else
|
220
|
+
super
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
227
224
|
# Quoting time without microseconds
|
228
225
|
def quoted_date(value)
|
229
226
|
if value.acts_like?(:time)
|
@@ -301,6 +298,7 @@ module ActiveRecord
|
|
301
298
|
options = apply_replica(table_name, options)
|
302
299
|
td = create_table_definition(apply_cluster(table_name), **options)
|
303
300
|
block.call td if block_given?
|
301
|
+
td.column(:id, options[:id], null: false) if options[:id].present? && td[:id].blank?
|
304
302
|
|
305
303
|
if options[:force]
|
306
304
|
drop_table(table_name, options.merge(if_exists: true))
|
@@ -341,8 +339,22 @@ module ActiveRecord
|
|
341
339
|
end
|
342
340
|
end
|
343
341
|
|
342
|
+
def add_column(table_name, column_name, type, **options)
|
343
|
+
return if options[:if_not_exists] == true && column_exists?(table_name, column_name, type)
|
344
|
+
|
345
|
+
at = create_alter_table table_name
|
346
|
+
at.add_column(column_name, type, **options)
|
347
|
+
execute(schema_creation.accept(at), nil, settings: {wait_end_of_query: 1, send_progress_in_http_headers: 1})
|
348
|
+
end
|
349
|
+
|
350
|
+
def remove_column(table_name, column_name, type = nil, **options)
|
351
|
+
return if options[:if_exists] == true && !column_exists?(table_name, column_name)
|
352
|
+
|
353
|
+
execute("ALTER TABLE #{quote_table_name(table_name)} #{remove_column_for_alter(table_name, column_name, type, **options)}", nil, settings: {wait_end_of_query: 1, send_progress_in_http_headers: 1})
|
354
|
+
end
|
355
|
+
|
344
356
|
def change_column(table_name, column_name, type, options = {})
|
345
|
-
result = do_execute
|
357
|
+
result = do_execute("ALTER TABLE #{quote_table_name(table_name)} #{change_column_for_alter(table_name, column_name, type, options)}", nil, settings: {wait_end_of_query: 1, send_progress_in_http_headers: 1})
|
346
358
|
raise "Error parse json response: #{result}" if result.presence && !result.is_a?(Hash)
|
347
359
|
end
|
348
360
|
|
@@ -4,6 +4,12 @@ module ClickhouseActiverecord
|
|
4
4
|
require 'rails'
|
5
5
|
|
6
6
|
class Railtie < Rails::Railtie
|
7
|
+
initializer "clickhouse.load" do
|
8
|
+
ActiveSupport.on_load :active_record do
|
9
|
+
ClickhouseActiverecord.load
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
7
13
|
rake_tasks { load 'tasks/clickhouse.rake' }
|
8
14
|
end
|
9
15
|
end
|
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'active_record/connection_adapters/clickhouse_adapter'
|
4
4
|
|
5
|
+
require 'core_extensions/active_record/relation'
|
6
|
+
|
5
7
|
require_relative '../core_extensions/active_record/migration/command_recorder'
|
6
8
|
ActiveRecord::Migration::CommandRecorder.include CoreExtensions::ActiveRecord::Migration::CommandRecorder
|
7
9
|
|
@@ -14,5 +16,7 @@ if defined?(Rails::Railtie)
|
|
14
16
|
end
|
15
17
|
|
16
18
|
module ClickhouseActiverecord
|
17
|
-
|
19
|
+
def self.load
|
20
|
+
ActiveRecord::Relation.prepend(CoreExtensions::ActiveRecord::Relation)
|
21
|
+
end
|
18
22
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module CoreExtensions
|
2
|
+
module ActiveRecord
|
3
|
+
module Relation
|
4
|
+
def reverse_order!
|
5
|
+
return super unless connection.is_a?(::ActiveRecord::ConnectionAdapters::ClickhouseAdapter)
|
6
|
+
|
7
|
+
orders = order_values.uniq.reject(&:blank?)
|
8
|
+
return super unless orders.empty? && !primary_key
|
9
|
+
|
10
|
+
self.order_values = (column_names & %w[date created_at]).map { |c| arel_table[c].desc }
|
11
|
+
self
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clickhouse-activerecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-02-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,13 +130,14 @@ files:
|
|
130
130
|
- lib/clickhouse-activerecord/schema_dumper.rb
|
131
131
|
- lib/clickhouse-activerecord/tasks.rb
|
132
132
|
- lib/clickhouse-activerecord/version.rb
|
133
|
+
- lib/core_extensions/active_record/relation.rb
|
133
134
|
- lib/generators/clickhouse_migration_generator.rb
|
134
135
|
- lib/tasks/clickhouse.rake
|
135
136
|
homepage: https://github.com/pnixx/clickhouse-activerecord
|
136
137
|
licenses:
|
137
138
|
- MIT
|
138
139
|
metadata: {}
|
139
|
-
post_install_message:
|
140
|
+
post_install_message:
|
140
141
|
rdoc_options: []
|
141
142
|
require_paths:
|
142
143
|
- lib
|
@@ -151,8 +152,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
152
|
- !ruby/object:Gem::Version
|
152
153
|
version: '0'
|
153
154
|
requirements: []
|
154
|
-
rubygems_version: 3.0.
|
155
|
-
signing_key:
|
155
|
+
rubygems_version: 3.0.4
|
156
|
+
signing_key:
|
156
157
|
specification_version: 4
|
157
158
|
summary: ClickHouse ActiveRecord
|
158
159
|
test_files: []
|