clickhouse-activerecord 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 823fdbf17f27c65446c01b1599a3c61d9fa9b310d7ce153e9c64a912719e552e
4
- data.tar.gz: 5b6dd44cdc44b2d1350e0f1c5937cf08051a5ff7a4f73cf56a5dc7567b4be800
3
+ metadata.gz: d56a19e32a58184c6c70b4cc56f30f4e7f742255a9f63441ce8c9b94ec63eebf
4
+ data.tar.gz: 2bd423580e61443e1b334e2182e4a05a7e712d79141ae6431730edcdc5dee7e3
5
5
  SHA512:
6
- metadata.gz: 5a8d48c078f5bf79a50fddf9b29ade13694019e8666c8c071e5b1ee7ab5b16c7e92116b794a82ce3fa6f927f0bd1186e7e87a65ed5f4eda0f1e6ed113f590de4
7
- data.tar.gz: 2be66ae7ac2cb71b20486685f00552890559f2944777d8557aabb60d2318baa868c3c4bc0cf4be82a97eeee920de0049851771253129022e8fbbb0758190f917
6
+ metadata.gz: 17a5a009eb6ece2d6835f5c37598891bde51fb4cf6c6e7ccb8fdc02cf9b1345d822e39d0f3d825b593606180db020357f4828e89f0c9c4cdf8352349ad6f4104
7
+ data.tar.gz: edc694713807b818d8f2e9c0b6a0592e0a3862a6b064d4110d12d82ebc1cb40133f7495e9e665007f91f0da5223d129ed110387f4922bf4de710729f462d4509
@@ -125,11 +125,7 @@ module ActiveRecord
125
125
  end
126
126
 
127
127
  def current_database
128
- if ActiveRecord::version >= Gem::Version.new('6.1')
129
- ActiveRecord::Base.connection_db_config.database
130
- else
131
- ActiveRecord::Base.connection_config[:database]
132
- end
128
+ ActiveRecord::Base.connection_db_config.database
133
129
  end
134
130
  end
135
131
  end
@@ -30,12 +30,16 @@ module ActiveRecord
30
30
  true
31
31
  end
32
32
 
33
+ # @link https://clickhouse.com/docs/en/sql-reference/statements/alter/update
33
34
  def exec_update(_sql, _name = nil, _binds = [])
34
- raise ActiveRecord::ActiveRecordError, 'Clickhouse update is not supported'
35
+ do_execute(_sql, _name, format: nil)
36
+ true
35
37
  end
36
38
 
39
+ # @link https://clickhouse.com/docs/en/sql-reference/statements/delete
37
40
  def exec_delete(_sql, _name = nil, _binds = [])
38
- raise ActiveRecord::ActiveRecordError, 'Clickhouse delete is not supported'
41
+ do_execute(_sql, _name, format: nil)
42
+ true
39
43
  end
40
44
 
41
45
  def tables(name = nil)
@@ -143,11 +147,7 @@ module ActiveRecord
143
147
  default = field[3]
144
148
  default_value = extract_value_from_default(default)
145
149
  default_function = extract_default_function(default_value, default)
146
- if ActiveRecord::version >= Gem::Version.new('6')
147
- ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), default_function)
148
- else
149
- ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), table_name, default_function)
150
- end
150
+ ClickhouseColumn.new(field[0], default_value, type_metadata, field[1].include?('Nullable'), default_function)
151
151
  end
152
152
 
153
153
  protected
@@ -127,9 +127,6 @@ module ActiveRecord
127
127
  @full_config = full_config
128
128
 
129
129
  @prepared_statements = false
130
- if ActiveRecord::version == Gem::Version.new('6.0.0')
131
- @prepared_statement_status = Concurrent::ThreadLocalVar.new(false)
132
- end
133
130
 
134
131
  connect
135
132
  end
@@ -238,30 +235,18 @@ module ActiveRecord
238
235
  # Quoting time without microseconds
239
236
  def quoted_date(value)
240
237
  if value.acts_like?(:time)
241
- if ActiveRecord::version >= Gem::Version.new('7')
242
- zone_conversion_method = ActiveRecord.default_timezone == :utc ? :getutc : :getlocal
243
- else
244
- zone_conversion_method = ActiveRecord::Base.default_timezone == :utc ? :getutc : :getlocal
245
- end
238
+ zone_conversion_method = ActiveRecord.default_timezone == :utc ? :getutc : :getlocal
246
239
 
247
240
  if value.respond_to?(zone_conversion_method)
248
241
  value = value.send(zone_conversion_method)
249
242
  end
250
243
  end
251
244
 
252
- if ActiveRecord::version >= Gem::Version.new('7')
253
- value.to_fs(:db)
254
- else
255
- value.to_s(:db)
256
- end
245
+ value.to_fs(:db)
257
246
  end
258
247
 
259
248
  def column_name_for_operation(operation, node) # :nodoc:
260
- if ActiveRecord::version >= Gem::Version.new('6')
261
- visitor.compile(node)
262
- else
263
- column_name_from_arel_node(node)
264
- end
249
+ visitor.compile(node)
265
250
  end
266
251
 
267
252
  # Executes insert +sql+ statement in the context of this connection using
@@ -23,6 +23,17 @@ module Arel
23
23
  maybe_visit o.settings, super
24
24
  end
25
25
 
26
+ def visit_Arel_Nodes_UpdateStatement(o, collector)
27
+ o = prepare_update_statement(o)
28
+
29
+ collector << 'ALTER TABLE '
30
+ collector = visit o.relation, collector
31
+ collect_nodes_for o.values, collector, ' UPDATE '
32
+ collect_nodes_for o.wheres, collector, ' WHERE ', ' AND '
33
+ collect_nodes_for o.orders, collector, ' ORDER BY '
34
+ maybe_visit o.limit, collector
35
+ end
36
+
26
37
  def visit_Arel_Nodes_Settings(o, collector)
27
38
  return collector if o.expr.empty?
28
39
 
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.1'
3
3
  end
@@ -72,7 +72,7 @@ namespace :clickhouse do
72
72
  desc 'Migrate the clickhouse database'
73
73
  task migrate: %i[prepare_schema_migration_table prepare_internal_metadata_table] do
74
74
  Rake::Task['db:migrate:clickhouse'].execute
75
- if File.exists? "#{Rails.root}/db/clickhouse_schema_simple.rb"
75
+ if File.exist? "#{Rails.root}/db/clickhouse_schema_simple.rb"
76
76
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
77
77
  end
78
78
  end
@@ -80,7 +80,7 @@ namespace :clickhouse do
80
80
  desc 'Rollback the clickhouse database'
81
81
  task rollback: %i[prepare_schema_migration_table prepare_internal_metadata_table] do
82
82
  Rake::Task['db:rollback:clickhouse'].execute
83
- if File.exists? "#{Rails.root}/db/clickhouse_schema_simple.rb"
83
+ if File.exist? "#{Rails.root}/db/clickhouse_schema_simple.rb"
84
84
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
85
85
  end
86
86
  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: 1.0.0
4
+ version: 1.0.1
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-29 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler