clickhouse-activerecord 1.0.3 → 1.0.4

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: a41725d372314184b6799381965f0fb299a42d27b5c714bd04ad768ab0f87a11
4
- data.tar.gz: 12e892096d7d76f039f484e58b045c9f680ee95297790f485f8b19d9ecca7412
3
+ metadata.gz: 194430a00c6f085ec0bf6b1cf18911c06b69ff2e87ef18fc50183b1d7d1f20c7
4
+ data.tar.gz: 54e418ac9c841e6852e7e87e1ea169335f0c0940537eda3f95d645f3e63ed81e
5
5
  SHA512:
6
- metadata.gz: 35afbee04dec61f61685ec9edd70a305df94fa2198933c9271f3221258f069be06a684dfd10a0a203798712ab1113f91b4f773d8c1f85f1455e4511b6437d6be
7
- data.tar.gz: 0b9adb5b3da648ab1ca1b44352b58fc91d7d09b0c29cbc816e23faa39b060ca3e7a8f35e67eb87e92332cae513592f19378fcf993c098684463ffbcd817d64e2
6
+ metadata.gz: 9d5a90636c9eaa390ce1b75f65581061312dd598fbaf64e0402a40d3e2a1ab6b8079a0ae438ac86e1b03d4df3a1d1ab6308db961cf988320a39b13cf65014cc5
7
+ data.tar.gz: d961eaf6d2d5798cbf220dc7249330c91b43fe86a68d64ff0371bb0a0f7cba754dd5e95fb1fb666fadcbd74fe71fd89f6ea5b2d85a6d478e7c624e541f00b768
@@ -64,7 +64,7 @@ module ActiveRecord
64
64
 
65
65
  def do_system_execute(sql, name = nil)
66
66
  log_with_debug(sql, "#{adapter_name} #{name}") do
67
- res = @connection.post("/?#{@config.to_param}", "#{sql} FORMAT JSONCompact", 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
67
+ res = @connection.post("/?#{@connection_config.to_param}", "#{sql} FORMAT JSONCompact", 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
68
68
 
69
69
  process_response(res)
70
70
  end
@@ -73,7 +73,7 @@ module ActiveRecord
73
73
  def do_execute(sql, name = nil, format: 'JSONCompact', settings: {})
74
74
  log(sql, "#{adapter_name} #{name}") do
75
75
  formatted_sql = apply_format(sql, format)
76
- request_params = @config || {}
76
+ request_params = @connection_config || {}
77
77
  res = @connection.post("/?#{request_params.merge(settings).to_param}", formatted_sql, 'User-Agent' => "Clickhouse ActiveRecord #{ClickhouseActiverecord::VERSION}")
78
78
 
79
79
  process_response(res)
@@ -100,6 +100,16 @@ module ActiveRecord
100
100
  end
101
101
  end
102
102
 
103
+ # Fix insert_all method
104
+ # https://github.com/PNixx/clickhouse-activerecord/issues/71#issuecomment-1923244983
105
+ def with_yaml_fallback(value) # :nodoc:
106
+ if value.is_a?(Array)
107
+ value
108
+ else
109
+ super
110
+ end
111
+ end
112
+
103
113
  private
104
114
 
105
115
  def apply_format(sql, format)
@@ -45,7 +45,7 @@ module ActiveRecord
45
45
  raise ArgumentError, 'No database specified. Missing argument: database.'
46
46
  end
47
47
 
48
- ConnectionAdapters::ClickhouseAdapter.new(logger, connection, { user: config[:username], password: config[:password], database: database }.compact, config)
48
+ ConnectionAdapters::ClickhouseAdapter.new(logger, connection, config)
49
49
  end
50
50
  end
51
51
  end
@@ -120,12 +120,12 @@ module ActiveRecord
120
120
  include Clickhouse::SchemaStatements
121
121
 
122
122
  # Initializes and connects a Clickhouse adapter.
123
- def initialize(logger, connection_parameters, config, full_config)
123
+ def initialize(logger, connection_parameters, config)
124
124
  super(nil, logger)
125
125
  @connection_parameters = connection_parameters
126
+ @connection_config = { user: config[:username], password: config[:password], database: config[:database] }.compact
127
+ @debug = config[:debug] || false
126
128
  @config = config
127
- @debug = full_config[:debug] || false
128
- @full_config = full_config
129
129
 
130
130
  @prepared_statements = false
131
131
 
@@ -133,7 +133,7 @@ module ActiveRecord
133
133
  end
134
134
 
135
135
  def migrations_paths
136
- @full_config[:migrations_paths] || 'db/migrate_clickhouse'
136
+ @config[:migrations_paths] || 'db/migrate_clickhouse'
137
137
  end
138
138
 
139
139
  def arel_visitor # :nodoc:
@@ -266,7 +266,7 @@ module ActiveRecord
266
266
  def create_database(name)
267
267
  sql = apply_cluster "CREATE DATABASE #{quote_table_name(name)}"
268
268
  log_with_debug(sql, adapter_name) do
269
- res = @connection.post("/?#{@config.except(:database).to_param}", sql)
269
+ res = @connection.post("/?#{@connection_config.except(:database).to_param}", sql)
270
270
  process_response(res)
271
271
  end
272
272
  end
@@ -302,7 +302,7 @@ module ActiveRecord
302
302
  raise 'Set a cluster' unless cluster
303
303
 
304
304
  distributed_options =
305
- "Distributed(#{cluster}, #{@config[:database]}, #{table_name}, #{sharding_key})"
305
+ "Distributed(#{cluster}, #{@connection_config[:database]}, #{table_name}, #{sharding_key})"
306
306
  create_table(distributed_table_name, **options.merge(options: distributed_options), &block)
307
307
  end
308
308
  end
@@ -311,7 +311,7 @@ module ActiveRecord
311
311
  def drop_database(name) #:nodoc:
312
312
  sql = apply_cluster "DROP DATABASE IF EXISTS #{quote_table_name(name)}"
313
313
  log_with_debug(sql, adapter_name) do
314
- res = @connection.post("/?#{@config.except(:database).to_param}", sql)
314
+ res = @connection.post("/?#{@connection_config.except(:database).to_param}", sql)
315
315
  process_response(res)
316
316
  end
317
317
  end
@@ -365,15 +365,15 @@ module ActiveRecord
365
365
  end
366
366
 
367
367
  def cluster
368
- @full_config[:cluster_name]
368
+ @config[:cluster_name]
369
369
  end
370
370
 
371
371
  def replica
372
- @full_config[:replica_name]
372
+ @config[:replica_name]
373
373
  end
374
374
 
375
375
  def use_default_replicated_merge_tree_params?
376
- database_engine_atomic? && @full_config[:use_default_replicated_merge_tree_params]
376
+ database_engine_atomic? && @config[:use_default_replicated_merge_tree_params]
377
377
  end
378
378
 
379
379
  def use_replica?
@@ -381,11 +381,11 @@ module ActiveRecord
381
381
  end
382
382
 
383
383
  def replica_path(table)
384
- "/clickhouse/tables/#{cluster}/#{@config[:database]}.#{table}"
384
+ "/clickhouse/tables/#{cluster}/#{@connection_config[:database]}.#{table}"
385
385
  end
386
386
 
387
387
  def database_engine_atomic?
388
- current_database_engine = "select engine from system.databases where name = '#{@config[:database]}'"
388
+ current_database_engine = "select engine from system.databases where name = '#{@connection_config[:database]}'"
389
389
  res = select_one(current_database_engine)
390
390
  res['engine'] == 'Atomic' if res
391
391
  end
@@ -53,6 +53,16 @@ module Arel
53
53
  collector
54
54
  end
55
55
 
56
+ def visit_Arel_Nodes_Matches(o, collector)
57
+ op = o.case_sensitive ? " LIKE " : " ILIKE "
58
+ infix_value o, collector, op
59
+ end
60
+
61
+ def visit_Arel_Nodes_DoesNotMatch(o, collector)
62
+ op = o.case_sensitive ? " NOT LIKE " : " NOT ILIKE "
63
+ infix_value o, collector, op
64
+ end
65
+
56
66
  def sanitize_as_setting_value(value)
57
67
  if value == :default
58
68
  'DEFAULT'
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -24,7 +24,7 @@ module CoreExtensions
24
24
  options: connection.adapter_name.downcase == 'clickhouse' ? 'ReplacingMergeTree(created_at) PARTITION BY key ORDER BY key' : '',
25
25
  if_not_exists: true
26
26
  }
27
- full_config = connection.instance_variable_get(:@full_config) || {}
27
+ full_config = connection.instance_variable_get(:@config) || {}
28
28
 
29
29
  if full_config[:distributed_service_tables]
30
30
  table_options.merge!(with_distributed: table_name, sharding_key: 'cityHash64(created_at)')
@@ -12,7 +12,7 @@ module CoreExtensions
12
12
  table_options = {
13
13
  id: false, options: 'ReplacingMergeTree(ver) ORDER BY (version)', if_not_exists: true
14
14
  }
15
- full_config = connection.instance_variable_get(:@full_config) || {}
15
+ full_config = connection.instance_variable_get(:@config) || {}
16
16
 
17
17
  if full_config[:distributed_service_tables]
18
18
  table_options.merge!(with_distributed: table_name, sharding_key: 'cityHash64(version)')
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.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergey Odintsov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-22 00:00:00.000000000 Z
11
+ date: 2024-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler