Skip to content

Commit

Permalink
support rails 6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Sep 2, 2019
1 parent 20226c3 commit 872a42b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Version 0.3.6 (Sep 2, 2019)

* Support Rails 6.0
* Fix relation `last` method

### Version 0.3.4 (Jun 28, 2019)

* Fix DateTime sql format without microseconds for Rails 5.2
Expand Down
2 changes: 1 addition & 1 deletion clickhouse-activerecord.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ['lib']

spec.add_runtime_dependency 'bundler', '>= 1.13.4'
spec.add_runtime_dependency 'activerecord', '~> 5.2'
spec.add_runtime_dependency 'activerecord', '>= 5.2'

spec.add_development_dependency 'bundler', '~> 1.15'
spec.add_development_dependency 'rake', '~> 10.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def new_column_from_field(table_name, field)
default = field[3]
default_value = extract_value_from_default(default)
default_function = extract_default_function(default_value, default)
ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), table_name, default_function)
if ActiveRecord::version >= Gem::Version.new('6')
ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), default_function)
else
ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), table_name, default_function)
end
end

protected
Expand Down
28 changes: 25 additions & 3 deletions lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

require 'clickhouse-activerecord/arel/visitors/to_sql'
require 'clickhouse-activerecord/arel/table'
require 'active_record/connection_adapters/abstract_adapter'
require 'active_record/connection_adapters/clickhouse/oid/date'
require 'active_record/connection_adapters/clickhouse/oid/date_time'
require 'active_record/connection_adapters/clickhouse/oid/big_integer'
Expand Down Expand Up @@ -31,6 +30,21 @@ def clickhouse_connection(config)
end
end

module QueryMethods

# Replace for only ClickhouseAdapter
def reverse_order!
orders = order_values.uniq
orders.reject!(&:blank?)
if self.connection.is_a?(ConnectionAdapters::ClickhouseAdapter) && orders.empty?
self.order_values = %w(date created_at).select {|c| column_names.include?(c) }.map{|c| arel_attribute(c).desc }
else
self.order_values = reverse_sql_order(orders)
end
self
end
end

module TypeCaster
class Map
def is_view
Expand Down Expand Up @@ -84,7 +98,11 @@ def initialize(connection, logger, connection_parameters, config, debug = false)
@config = config
@debug = debug

@prepared_statements = false
if ActiveRecord::version >= Gem::Version.new('6')
@prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
else
@prepared_statements = false
end

connect
end
Expand Down Expand Up @@ -145,7 +163,11 @@ def quoted_date(value)
end

def column_name_for_operation(operation, node) # :nodoc:
column_name_from_arel_node(node)
if ActiveRecord::version >= Gem::Version.new('6')
visitor.compile(node)
else
column_name_from_arel_node(node)
end
end

# Executes insert +sql+ statement in the context of this connection using
Expand Down
2 changes: 1 addition & 1 deletion lib/clickhouse-activerecord/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module ClickhouseActiverecord
VERSION = '0.3.5'
VERSION = '0.3.7'
end

0 comments on commit 872a42b

Please sign in to comment.