Skip to content

Commit

Permalink
Fix DateTime sql format without microseconds for Rails 5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
PNixx committed Jun 28, 2019
1 parent f6cac1a commit bd76e48
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
### Version 0.3.4 (Jun 28, 2019)

* Fix DateTime sql format without microseconds for Rails 5.2
* Support ssl connection
* Migration support
* Rake tasks for create / drop database

### Version 0.3.0 (Nov 27, 2018)

* Support materialized view
Expand Down
8 changes: 4 additions & 4 deletions clickhouse-activerecord.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

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

spec.add_development_dependency 'bundler', '~> 1.15'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'rspec', '~> 3.4'
spec.add_development_dependency 'pry', '~> 0.12'
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class DateTime < Type::DateTime # :nodoc:

def serialize(value)
value = super
return value unless value.acts_like?(:time)
return value.strftime('%Y-%m-%d %H:%M:%S') unless value.acts_like?(:time)

value.to_time.strftime('%Y-%m-%d %H:%M:%S')
end
Expand Down
13 changes: 13 additions & 0 deletions lib/active_record/connection_adapters/clickhouse_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ def initialize_type_map(m) # :nodoc:
register_class_with_limit m, %r(Int64), Type::Integer
end

# Quoting time without microseconds
def quoted_date(value)
if value.acts_like?(:time)
zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal

if value.respond_to?(zone_conversion_method)
value = value.send(zone_conversion_method)
end
end

value.to_s(:db)
end

# Executes insert +sql+ statement in the context of this connection using
# +binds+ as the bind substitutes. +name+ is logged along with
# the executed +sql+ statement.
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.3'
VERSION = '0.3.4'
end

0 comments on commit bd76e48

Please sign in to comment.