optic-rails 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c86b9eac93434bd8297c433d5f10c4c1827e4905cf4c7d6e62fe5f4c3ee6fec
4
- data.tar.gz: 2c15c7a1cb011386bc64f632af5b49b571289773195f44dedc3fced6d78ea65c
3
+ metadata.gz: f9410ea4eb57b65685d90e10085ae84f5e40607ed9f1a1016c147c1c3c231efe
4
+ data.tar.gz: adc15f1add9ac36ccdf2ca8be14a369ab2ba6475072e2298c963d52ddd597d97
5
5
  SHA512:
6
- metadata.gz: 1c35b4031d5c8c6ca5aa4e1e10d7955c5db635d29208bcfe7e69042cd3586bb9e65b2382935525c209ee9262dce93538d71ebcd31dc98ac1ab3a0805f6b06f34
7
- data.tar.gz: 01432f5d8f521e78d12c60e2e4e686cbf95b6c4995f1fb5366d9293236527affbd6c117020dda37df3c806e977a49106c9bf6973b1acfeb0dfc4c7ab34ef8ebd
6
+ metadata.gz: 732f7902ece59b40ec446b17615836b490ba2e94bea9f72ff0b75439274e878f32d85fd057d6854077314256141aa6b8e57dd485cc5c61f72732704097a3b31a
7
+ data.tar.gz: a53b1d9fb359101ae9a51eb90a0e32c292440a19b951aae377c17a328b591e03f84df378fc15589fdb98c6f6acbd705dd5654d47176d40736059552093c2f063
@@ -52,30 +52,30 @@ module Optic
52
52
  joins = join_path.reverse.map(&:to_sym).inject { |acc, elt| { elt => acc } }
53
53
 
54
54
  columns = [
55
- %Q|#{qualified_primary_key(pivot)} AS "primary_key"|,
56
- %Q|#{qualified_column(pivot, instruction["pivot_attribute_name"])} AS "pivot_attribute_name"|,
55
+ %Q|#{qualified_primary_key(connection, pivot)} AS primary_key|,
56
+ %Q|#{qualified_entity_column(connection, pivot, instruction["pivot_attribute_name"])} AS pivot_attribute_name|,
57
57
  ]
58
58
 
59
59
  join_select = entity
60
60
  .joins(joins)
61
- .group(qualified_primary_key(pivot))
62
- .select(*columns, 'COUNT(*) AS "count"')
61
+ .group(qualified_primary_key(connection, pivot))
62
+ .select(*columns, 'COUNT(*) AS count')
63
63
  .to_sql
64
64
 
65
65
  instance_select = pivot
66
- .select(*columns, '0 AS "count"')
66
+ .select(*columns, '0 AS count')
67
67
  .to_sql
68
68
 
69
69
  union_sql = <<~"SQL"
70
- SELECT "pivot_values"."primary_key", "pivot_values"."pivot_attribute_name", MAX("pivot_values"."count") AS "count"
71
- FROM (#{join_select} UNION ALL #{instance_select}) AS "pivot_values"
72
- GROUP BY "pivot_values"."primary_key", "pivot_values"."pivot_attribute_name"
70
+ SELECT pivot_values.primary_key, pivot_values.pivot_attribute_name, MAX(pivot_values.count) AS count
71
+ FROM (#{join_select} UNION ALL #{instance_select}) AS pivot_values
72
+ GROUP BY pivot_values.primary_key, pivot_values.pivot_attribute_name
73
73
  SQL
74
74
  else
75
- entity.select("COUNT(*)").to_sql
75
+ entity.select('COUNT(*) as count').to_sql
76
76
  end
77
77
 
78
- { metric_configuration_id: instruction["metric_configuration_id"], result: connection.execute(query).to_a }
78
+ { metric_configuration_id: instruction["metric_configuration_id"], result: connection.exec_query(query).to_a }
79
79
  end
80
80
  end
81
81
  end
@@ -89,8 +89,12 @@ module Optic
89
89
  def with_connection
90
90
  ActiveRecord::Base.connection_pool.with_connection do |connection|
91
91
  connection.transaction do
92
- connection.execute "SET TRANSACTION READ ONLY"
93
- connection.execute "SET LOCAL statement_timeout = 100"
92
+ if connection.adapter_name == "PostgreSQL"
93
+ connection.execute "SET TRANSACTION READ ONLY"
94
+ connection.execute "SET LOCAL statement_timeout = 100"
95
+ # TODO support equivalent options for other adapters (such as mysql)
96
+ end
97
+
94
98
  yield connection
95
99
  end
96
100
  end
@@ -100,12 +104,16 @@ module Optic
100
104
  entity_name.constantize.unscoped
101
105
  end
102
106
 
103
- def qualified_column(entity, attribute)
104
- %Q|"#{entity.table_name}"."#{attribute}"|
107
+ def qualified_primary_key(connection, entity)
108
+ qualified_entity_column(connection, entity, entity.primary_key)
109
+ end
110
+
111
+ def qualified_entity_column(connection, entity, attribute)
112
+ qualified_table_column(connection, entity.table_name, attribute)
105
113
  end
106
114
 
107
- def qualified_primary_key(entity)
108
- qualified_column(entity, entity.primary_key)
115
+ def qualified_table_column(connection, table_name, column_name)
116
+ connection.quote_table_name(table_name) + "." + connection.quote_column_name(column_name)
109
117
  end
110
118
 
111
119
  def active_record_klasses
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Optic
4
4
  module Rails
5
- VERSION = "1.3.1"
5
+ VERSION = "1.3.2"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optic-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anton Vaynshtok
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-03 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: action_cable_client