clickhouse-activerecord 1.1.1 → 1.1.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: 33b7616478a348a6d6cb1566fbf48bf5e1bad4f0dbb72269eb9befd851416121
4
- data.tar.gz: d6479be11b4f06096e7fdf24bb75742e1ac2381e671918088ca05f83960bd6a9
3
+ metadata.gz: 7c1652d6cf040ebaf43559441ccfa2496f4c408b232ca6d3d1c71da9bbc20209
4
+ data.tar.gz: 900d15344b100536b6f1e0ac1dd3e1df03b890fe5c1b6f7b6f9218283156c17f
5
5
  SHA512:
6
- metadata.gz: dc19098e7e42c154e6255a90e6abf4e46d4546658c8db1b8ade27caa3e73e3fb29636e64c05c3160522a9bdd8c12f95b515300a637453e05a520a6d92746b248
7
- data.tar.gz: 64c7023e7cc381696a6f97ae8fa3b5ed20cdf6d971bc7f852a8403895ce62d0274fddc3325978f6d733b086e322967c7b827e94bc10e09da364fc7fd040081fe
6
+ metadata.gz: d9a74ee0ca1e865f821d5c8a1f8612e30dcd790cd79725344ab568b246d30d895711a69f5f05542ff1989f194605a70d7906ec432c90bf2c0688f5a5b120b3ab
7
+ data.tar.gz: ddb82724f85c5a2cfb6da4db250d20f9fc6eb7cddf91a8bada889f07eb717f8657ad011d71e2ab19cb625b83b74dad91a8adeb1bcf94886f33fbd2cd999cc833
data/CHANGELOG.md CHANGED
@@ -1,3 +1,15 @@
1
+ ### Version 1.1.2 (Aug 27, 2024)
2
+ * 🎉 Support for rails 7.2 #156
3
+ * Add method `views` for getting table `View` list in #152
4
+ * Add support for Map datatype in #144
5
+ * Add support window named functions
6
+ * Fix schema dumper default values for number
7
+ * Normalize table name in schema dump in #148
8
+ * Noop savepoint functionality in #150
9
+ * Fix `#find_by` in #153
10
+ * Add RSpec configure
11
+ * Fix detect model primary key
12
+
1
13
  ### Version 1.0.7 (Apr 27, 2024)
2
14
 
3
15
  * Support table indexes
@@ -6,11 +6,11 @@ module ActiveRecord
6
6
 
7
7
  module ClassMethods # :nodoc:
8
8
  def quote_column_name(name)
9
- name
9
+ name.to_s.include?('.') ? "`#{name}`" : name.to_s
10
10
  end
11
11
 
12
12
  def quote_table_name(name)
13
- name
13
+ name.to_s
14
14
  end
15
15
  end
16
16
  end
@@ -47,7 +47,7 @@ module ActiveRecord
47
47
 
48
48
  module ModelSchema
49
49
  module ClassMethods
50
- delegate :final, :final!, :settings, :settings!, to: :all
50
+ delegate :final, :final!, :settings, :settings!, :window, :window!, to: :all
51
51
 
52
52
  def is_view
53
53
  @is_view || false
@@ -142,6 +142,11 @@ module ActiveRecord
142
142
  connect
143
143
  end
144
144
 
145
+ # Return ClickHouse server version
146
+ def server_version
147
+ @server_version ||= do_system_execute('SELECT version()')['data'][0][0]
148
+ end
149
+
145
150
  # Savepoints are not supported, noop
146
151
  def create_savepoint(name)
147
152
  end
@@ -276,10 +281,15 @@ module ActiveRecord
276
281
 
277
282
  # SCHEMA STATEMENTS ========================================
278
283
 
279
- def primary_key(table_name) #:nodoc:
284
+ def primary_keys(table_name)
285
+ if server_version.to_f >= 23.4
286
+ structure = do_system_execute("SHOW COLUMNS FROM `#{table_name}`")
287
+ return structure['data'].select {|m| m[3]&.include?('PRI') }.pluck(0)
288
+ end
289
+
280
290
  pk = table_structure(table_name).first
281
- return 'id' if pk.present? && pk[0] == 'id'
282
- false
291
+ return ['id'] if pk.present? && pk[0] == 'id'
292
+ []
283
293
  end
284
294
 
285
295
  def create_schema_dumper(options) # :nodoc:
@@ -74,6 +74,14 @@ module Arel
74
74
  infix_value o, collector, op
75
75
  end
76
76
 
77
+ def visit_Arel_Nodes_Rows(o, collector)
78
+ if o.expr.is_a?(String)
79
+ collector << "ROWS #{o.expr}"
80
+ else
81
+ super
82
+ end
83
+ end
84
+
77
85
  def sanitize_as_setting_value(value)
78
86
  if value == :default
79
87
  'DEFAULT'
@@ -1,3 +1,3 @@
1
1
  module ClickhouseActiverecord
2
- VERSION = '1.1.1'
2
+ VERSION = '1.1.2'
3
3
  end
@@ -64,6 +64,23 @@ module CoreExtensions
64
64
  self
65
65
  end
66
66
 
67
+ # Windows functions let you perform calculations across a set of rows that are related to the current row. For example:
68
+ #
69
+ # users = User.window('x', order: 'date', partition: 'name', rows: 'UNBOUNDED PRECEDING').select('sum(value) OVER x')
70
+ # # SELECT sum(value) OVER x FROM users WINDOW x AS (PARTITION BY name ORDER BY date ROWS UNBOUNDED PRECEDING)
71
+ #
72
+ # @param [String] name
73
+ # @param [Hash] opts
74
+ def window(name, **opts)
75
+ spawn.window!(name, **opts)
76
+ end
77
+
78
+ def window!(name, **opts)
79
+ @values[:windows] = [] unless @values[:windows]
80
+ @values[:windows] << [name, opts]
81
+ self
82
+ end
83
+
67
84
  private
68
85
 
69
86
  def check_command(cmd)
@@ -80,6 +97,7 @@ module CoreExtensions
80
97
  arel.final! if @values[:final].present?
81
98
  arel.settings(@values[:settings]) if @values[:settings].present?
82
99
  arel.using(@values[:using]) if @values[:using].present?
100
+ arel.windows(@values[:windows]) if @values[:windows].present?
83
101
 
84
102
  arel
85
103
  end
@@ -13,6 +13,18 @@ module CoreExtensions
13
13
  self
14
14
  end
15
15
 
16
+ # @param [Array] windows
17
+ def windows(windows)
18
+ @ctx.windows = windows.map do |name, opts|
19
+ # https://github.com/rails/rails/blob/main/activerecord/test/cases/arel/select_manager_test.rb#L790
20
+ window = ::Arel::Nodes::NamedWindow.new(name)
21
+ opts.each do |key, value|
22
+ window.send(key, value)
23
+ end
24
+ window
25
+ end
26
+ end
27
+
16
28
  def using(*exprs)
17
29
  @ctx.source.right.last.right = ::Arel::Nodes::Using.new(::Arel.sql(exprs.join(',')))
18
30
  self
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.1.1
4
+ version: 1.1.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: 2024-08-19 00:00:00.000000000 Z
11
+ date: 2024-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler