diff --git a/lib/active_record/connection_adapters/clickhouse/oid/map.rb b/lib/active_record/connection_adapters/clickhouse/oid/map.rb index 6c6a1879..239d2734 100644 --- a/lib/active_record/connection_adapters/clickhouse/oid/map.rb +++ b/lib/active_record/connection_adapters/clickhouse/oid/map.rb @@ -33,7 +33,10 @@ def deserialize(value) def serialize(value) return '{}' if value.nil? - "{#{value.map { |k, v| "'#{k}': '#{v}'" }.join(', ')}}" + res = value.map { |k, v| "#{quote(k)}: #{quote(v)}" }.join(', ') + res = "{#{res}}" + + res end private @@ -48,10 +51,23 @@ def cast_type(type) :datetime when /Date/ :date + when /Array\(*\)/ + type else :string end end + + def quote(value) + case value + when String, Symbol + "'#{value}'" + when ::Array + "[#{value.map { |v| quote(v) }.join(', ')}]" + else + value + end + end end end end diff --git a/lib/active_record/connection_adapters/clickhouse_adapter.rb b/lib/active_record/connection_adapters/clickhouse_adapter.rb index 8c98cf2c..8e036726 100644 --- a/lib/active_record/connection_adapters/clickhouse_adapter.rb +++ b/lib/active_record/connection_adapters/clickhouse_adapter.rb @@ -112,6 +112,8 @@ def cast_type(type) :datetime when /Date/ :date + when /Array/ + type else :string end @@ -267,6 +269,8 @@ def quote(value) case value when Array '[' + value.map { |v| quote(v) }.join(', ') + ']' + when Hash + '{' + value.map { |k, v| "#{quote(k)}: #{quote(v)}" }.join(', ') + '}' else super end