clickhouse-activerecord 1.0.0 → 1.0.2

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: e5a31d2ddff53bb618e1624e325c0be76f2f602655565a74a96106674f3a375e
4
+ data.tar.gz: 762b41c929d36e7ff0f0ceff557da5b85d0b231e8df3e6c6bd41b6085eb940b0
5
5
  SHA512:
6
- metadata.gz: 5a8d48c078f5bf79a50fddf9b29ade13694019e8666c8c071e5b1ee7ab5b16c7e92116b794a82ce3fa6f927f0bd1186e7e87a65ed5f4eda0f1e6ed113f590de4
7
- data.tar.gz: 2be66ae7ac2cb71b20486685f00552890559f2944777d8557aabb60d2318baa868c3c4bc0cf4be82a97eeee920de0049851771253129022e8fbbb0758190f917
6
+ metadata.gz: a6f8143c312efbc6f276b0fdc2b9e5ea8ab811f06a865d54ff82dcaa0614c30b26c44f65f60098f0895dcf935aa97c86e8b168e7e1bc5b7e54899662b71ad86a
7
+ data.tar.gz: d9f4ba22a3f13bd157a225870e4d5eb025ca6a35ac21dc73731c19a8bb0d7464e479479109007d117d29f1aa788bb2f3cd5ae0350f1fa13596c36da3ed99a766
@@ -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
@@ -68,10 +68,9 @@ module ActiveRecord
68
68
 
69
69
  if options[:precision]
70
70
  kind = :datetime64
71
- options[:value] = options[:precision]
72
71
  end
73
72
 
74
- args.each { |name| column(name, kind, **options.except(:precision)) }
73
+ args.each { |name| column(name, kind, **options) }
75
74
  end
76
75
 
77
76
  def uuid(*args, **options)
@@ -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,19 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ClickhouseActiverecord
4
-
5
4
  class Schema < ::ActiveRecord::Schema
6
5
 
7
- def define(info, &block) # :nodoc:
8
- instance_eval(&block)
9
-
10
- if info[:version].present?
11
- connection.schema_migration.create_table
12
- connection.assume_migrated_upto_version(info[:version], ClickhouseActiverecord::Migrator.migrations_paths)
13
- end
14
-
15
- ClickhouseActiverecord::InternalMetadata.create_table
16
- ClickhouseActiverecord::InternalMetadata[:environment] = connection.migration_context.current_environment
17
- end
18
6
  end
19
7
  end
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '1.0.0'
2
+ VERSION = '1.0.2'
3
3
  end
@@ -14,9 +14,10 @@ namespace :clickhouse do
14
14
  namespace :schema do
15
15
  # TODO: not testing
16
16
  desc 'Load database schema'
17
- task load: %i[load_config prepare_internal_metadata_table] do
17
+ task load: %i[prepare_internal_metadata_table] do
18
18
  simple = ENV['simple'] || ARGV.any? { |a| a.include?('--simple') } ? '_simple' : nil
19
- ClickhouseActiverecord::SchemaMigration.drop_table
19
+ config = ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: 'clickhouse')
20
+ ClickhouseActiverecord::SchemaMigration.new(ActiveRecord::Base.establish_connection(config).connection).drop_table
20
21
  load(Rails.root.join("db/clickhouse_schema#{simple}.rb"))
21
22
  end
22
23
 
@@ -72,7 +73,7 @@ namespace :clickhouse do
72
73
  desc 'Migrate the clickhouse database'
73
74
  task migrate: %i[prepare_schema_migration_table prepare_internal_metadata_table] do
74
75
  Rake::Task['db:migrate:clickhouse'].execute
75
- if File.exists? "#{Rails.root}/db/clickhouse_schema_simple.rb"
76
+ if File.exist? "#{Rails.root}/db/clickhouse_schema_simple.rb"
76
77
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
77
78
  end
78
79
  end
@@ -80,7 +81,7 @@ namespace :clickhouse do
80
81
  desc 'Rollback the clickhouse database'
81
82
  task rollback: %i[prepare_schema_migration_table prepare_internal_metadata_table] do
82
83
  Rake::Task['db:rollback:clickhouse'].execute
83
- if File.exists? "#{Rails.root}/db/clickhouse_schema_simple.rb"
84
+ if File.exist? "#{Rails.root}/db/clickhouse_schema_simple.rb"
84
85
  Rake::Task['clickhouse:schema:dump'].execute(simple: true)
85
86
  end
86
87
  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.2
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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler