clickhouse-activerecord 0.5.13 → 0.5.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_record/connection_adapters/clickhouse/oid/date_time.rb +1 -2
- data/lib/active_record/connection_adapters/clickhouse_adapter.rb +17 -16
- 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 +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6534694860bbb41c21789239e0589406bcbef64bc1750645c68485e77acb7310
|
4
|
+
data.tar.gz: c6640ccc74004a93bfaa18d93dd1c135411d66f27273eb65848f9843f64fd6d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f848ad57f80f061aa85a593a90bff65707e8dbe281caf3f4a41914d93a4723351bf7e5ca12bfdc7c8ed2cbed5df3db39472b8d015645875476b68941d7de6111
|
7
|
+
data.tar.gz: 1592560741198e983d43599ff78b145262e0638951a2825dcaac993e0dcc0195bf85980b5eeff80d973e0573aeaa865d6d6c8acdd7ee2b2b1ba6bb6740e734cf
|
@@ -9,9 +9,8 @@ module ActiveRecord
|
|
9
9
|
def serialize(value)
|
10
10
|
value = super
|
11
11
|
return unless value
|
12
|
-
return value.strftime('%Y-%m-%d %H:%M:%S') unless value.acts_like?(:time)
|
13
12
|
|
14
|
-
value.
|
13
|
+
value.strftime('%Y-%m-%d %H:%M:%S' + (@precision.present? && @precision > 0 ? ".%#{@precision}N" : ''))
|
15
14
|
end
|
16
15
|
|
17
16
|
def type_cast_from_database(value)
|
@@ -48,19 +48,6 @@ module ActiveRecord
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
module ClickhouseRelationReverseOrder
|
52
|
-
def reverse_order!
|
53
|
-
return super unless connection.is_a?(ConnectionAdapters::ClickhouseAdapter)
|
54
|
-
|
55
|
-
orders = order_values.uniq.compact_blank
|
56
|
-
return super unless orders.empty? && !primary_key
|
57
|
-
|
58
|
-
self.order_values = %w(date created_at).select {|c| column_names.include?(c) }.map{|c| arel_attribute(c).desc }
|
59
|
-
self
|
60
|
-
end
|
61
|
-
end
|
62
|
-
Relation.prepend(ClickhouseRelationReverseOrder)
|
63
|
-
|
64
51
|
module TypeCaster
|
65
52
|
class Map
|
66
53
|
def is_view
|
@@ -74,7 +61,7 @@ module ActiveRecord
|
|
74
61
|
end
|
75
62
|
|
76
63
|
module ModelSchema
|
77
|
-
|
64
|
+
module ClassMethods
|
78
65
|
def is_view
|
79
66
|
@is_view || false
|
80
67
|
end
|
@@ -204,7 +191,7 @@ module ActiveRecord
|
|
204
191
|
super
|
205
192
|
register_class_with_limit m, %r(String), Type::String
|
206
193
|
register_class_with_limit m, 'Date', Clickhouse::OID::Date
|
207
|
-
|
194
|
+
register_class_with_precision m, %r(datetime)i, Clickhouse::OID::DateTime
|
208
195
|
|
209
196
|
register_class_with_limit m, %r(Int8), Type::Integer
|
210
197
|
register_class_with_limit m, %r(Int16), Type::Integer
|
@@ -352,8 +339,22 @@ module ActiveRecord
|
|
352
339
|
end
|
353
340
|
end
|
354
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
|
+
|
355
356
|
def change_column(table_name, column_name, type, options = {})
|
356
|
-
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})
|
357
358
|
raise "Error parse json response: #{result}" if result.presence && !result.is_a?(Hash)
|
358
359
|
end
|
359
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergey Odintsov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -130,6 +130,7 @@ 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
|