sunstone 7.1.0.1 → 7.2.0

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: 3956ea045dce2994b10bcac8535462bdf08597b85d7e15fc325110149a576aa6
4
- data.tar.gz: 02be730df372f32557112e9fb618befb5aafd7a8ef15ce1e12a866f8c18c2ed7
3
+ metadata.gz: d280487f58777eebd36b07eb69f9492b77370ea3def7b05321bb2d4fd8e55626
4
+ data.tar.gz: a34f616483aca20b1207f12538e08fafb19b16ac01db6c19977b902cd1cd1537
5
5
  SHA512:
6
- metadata.gz: c978ff5919d301007ccd326a632ed915cce129584e0ff9c25c199bddb9a65e517361f95a7d3a8af4ea70546acd1bb16fbc1118ff050a0c209f4168f9ec71feb9
7
- data.tar.gz: 3a24f347b5ca8ccf2816e8d50a28ca3effedea79a897ab3692801b5cd8095d9fc324f37f792ffba621a9669eb7ea92f58be762b62d2a1e9096a9306fc1d46be9
6
+ metadata.gz: 0211de6c05fded268d04e00af2e0f16e9f4ee0650307288ea890c343e1b20f0a2fcf924631e2c0c3e72b602af7e964c8663a6df51f22cce9bd85798b26d12604
7
+ data.tar.gz: 62e9b986925a43ca27c172499bca956ea20e6b8ca237d94dbcb1b07f52772ad1ffc9d5a0fe68d9ef6560e9a3df5ccc7bc27a8a78b56aad4fcccc44604f2a9060
@@ -6,7 +6,7 @@ module ActiveRecord
6
6
 
7
7
  def replace(other_array)
8
8
  other_array.each { |val| raise_on_type_mismatch!(val) }
9
- original_target = load_target.dup
9
+ original_target = skip_strict_loading { load_target }.dup
10
10
 
11
11
  if owner.new_record?
12
12
  replace_records(other_array, original_target)
@@ -52,7 +52,6 @@ module ActiveRecord
52
52
  end
53
53
  end
54
54
 
55
-
56
55
  end
57
56
 
58
57
  class HasManyThroughAssociation
@@ -25,13 +25,13 @@ module ActiveRecord
25
25
 
26
26
  include Module.new {
27
27
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
28
- def destroy_associations
29
- if !self.class.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
30
- association(:#{middle_reflection.name}).delete_all(:delete_all)
31
- association(:#{name}).reset
28
+ def destroy_associations
29
+ if !self.class.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
30
+ association(:#{middle_reflection.name}).delete_all(:delete_all)
31
+ association(:#{name}).reset
32
+ end
33
+ super
32
34
  end
33
- super
34
- end
35
35
  RUBY
36
36
  }
37
37
 
@@ -44,7 +44,7 @@ module ActiveRecord
44
44
  end
45
45
 
46
46
  has_many name, scope, **hm_options, &extension
47
- _reflections[name.to_s].parent_reflection = habtm_reflection
47
+ _reflections[name].parent_reflection = habtm_reflection
48
48
  end
49
49
  end
50
50
  end
@@ -104,18 +104,22 @@ module ActiveRecord
104
104
  def _create_record(attribute_names = self.attribute_names)
105
105
  attribute_names = attributes_for_create(attribute_names)
106
106
  attribute_values = attributes_with_values(attribute_names)
107
-
108
- returning_columns = self.class._returning_columns_for_insert
109
-
110
- returning_values = self.class._insert_record(
111
- attribute_values,
112
- returning_columns
113
- )
114
-
115
- if !self.class.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
116
- returning_columns.zip(returning_values).each do |column, value|
117
- _write_attribute(column, value) if !_read_attribute(column)
118
- end if returning_values
107
+ returning_values = nil
108
+
109
+ self.class.with_connection do |connection|
110
+ returning_columns = self.class._returning_columns_for_insert(connection)
111
+
112
+ returning_values = self.class._insert_record(
113
+ connection,
114
+ attribute_values,
115
+ returning_columns
116
+ )
117
+
118
+ if !self.class.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
119
+ returning_columns.zip(returning_values).each do |column, value|
120
+ _write_attribute(column, value) if !_read_attribute(column)
121
+ end if returning_values
122
+ end
119
123
  end
120
124
 
121
125
  @new_record = false
@@ -5,10 +5,23 @@ module ActiveRecord
5
5
  module Calculations
6
6
 
7
7
  def pluck(*column_names)
8
+ if @none
9
+ if @async
10
+ return Promise::Complete.new([])
11
+ else
12
+ return []
13
+ end
14
+ end
15
+
8
16
  if loaded? && all_attributes?(column_names)
9
- return records.pluck(*column_names)
17
+ result = records.pluck(*column_names)
18
+ if @async
19
+ return Promise::Complete.new(result)
20
+ else
21
+ return result
22
+ end
10
23
  end
11
-
24
+
12
25
  if has_include?(column_names.first)
13
26
  relation = apply_join_dependency
14
27
  relation.pluck(*column_names)
@@ -16,18 +29,22 @@ module ActiveRecord
16
29
  load
17
30
  return records.pluck(*column_names.map{|n| n.to_s.sub(/^#{klass.table_name}\./, "")})
18
31
  else
19
- klass.disallow_raw_sql!(column_names)
32
+ klass.disallow_raw_sql!(flattened_args(column_names))
20
33
  columns = arel_columns(column_names)
21
34
  relation = spawn
22
35
  relation.select_values = columns
23
36
  result = skip_query_cache_if_necessary do
24
37
  if where_clause.contradiction?
25
- ActiveRecord::Result.empty
38
+ ActiveRecord::Result.empty(async: @async)
26
39
  else
27
- klass.connection.select_all(relation.arel, "#{klass.name} Pluck")
40
+ klass.with_connection do |c|
41
+ c.select_all(relation.arel, "#{klass.name} Pluck", async: @async)
42
+ end
28
43
  end
29
44
  end
30
- type_cast_pluck_values(result, columns)
45
+ result.then do |result|
46
+ type_cast_pluck_values(result, columns)
47
+ end
31
48
  end
32
49
  end
33
50
 
@@ -1,9 +1,11 @@
1
1
  module ActiveRecord
2
2
  module QueryMethods
3
3
  private
4
- def assert_mutability!
5
- raise ImmutableRelation if @loaded
6
- raise ImmutableRelation if defined?(@arel) && @arel && !klass.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
7
- end
4
+
5
+ def assert_modifiable!
6
+ raise UnmodifiableRelation if @loaded
7
+ raise UnmodifiableRelation if @arel && !klass.connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter)
8
+ end
9
+
8
10
  end
9
11
  end
@@ -34,23 +34,25 @@ module ActiveRecord
34
34
  # end
35
35
 
36
36
  def with_transaction_returning_status
37
- status = nil
38
- connection = self.class.connection
39
-
40
- if connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter) && instance_variable_defined?(:@sunstone_updating) && @sunstone_updating
41
- status = yield
42
- else
43
- ensure_finalize = !connection.transaction_open?
44
- connection.transaction do
45
- add_to_transaction(ensure_finalize || has_transactional_callbacks?)
46
- remember_transaction_record_state
37
+ self.class.with_connection do |connection|
38
+ status = nil
39
+ # connection = self.class.connection
47
40
 
41
+ if connection.is_a?(ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter) && instance_variable_defined?(:@sunstone_updating) && @sunstone_updating
48
42
  status = yield
49
- raise ActiveRecord::Rollback unless status
43
+ else
44
+ ensure_finalize = !connection.transaction_open?
45
+ connection.transaction do
46
+ add_to_transaction(ensure_finalize || has_transactional_callbacks?)
47
+ remember_transaction_record_state
48
+
49
+ status = yield
50
+ raise ActiveRecord::Rollback unless status
51
+ end
50
52
  end
51
- end
52
53
 
53
- status
54
+ status
55
+ end
54
56
  end
55
57
 
56
58
 
@@ -29,8 +29,7 @@ module ActiveRecord
29
29
  sar.compile(binds)
30
30
  end
31
31
 
32
- def to_sar_and_binds(arel_or_sar_string, binds = [], preparable = nil) # :nodoc:
33
- # Arel::TreeManager -> Arel::Node
32
+ def to_sar_and_binds(arel_or_sar_string, binds = [], preparable = nil, allow_retry = false)
34
33
  if arel_or_sar_string.respond_to?(:ast)
35
34
  arel_or_sar_string = arel_or_sar_string.ast
36
35
  end
@@ -42,9 +41,9 @@ module ActiveRecord
42
41
  end
43
42
 
44
43
  sar = visitor.accept(arel_or_sar_string, collector)
45
- [sar.freeze, sar.binds, false]
44
+ [sar.freeze, sar.binds, false, allow_retry]
46
45
  else
47
- [arel_or_sar_string.dup.freeze, binds, false]
46
+ [arel_or_sar_string.dup.freeze, binds, false, allow_retry]
48
47
  end
49
48
  end
50
49
 
@@ -90,11 +89,15 @@ module ActiveRecord
90
89
  end
91
90
 
92
91
  # Returns an ActiveRecord::Result instance.
93
- def select_all(arel, name = nil, binds = [], preparable: nil, async: false)
92
+ def select_all(arel, name = nil, binds = [], preparable: nil, async: false, allow_retry: false)
94
93
  arel = arel_from_relation(arel)
95
- sar, binds, preparable = to_sar_and_binds(arel, binds, preparable)
94
+ sar, binds, preparable, allow_retry = to_sar_and_binds(arel, binds, preparable, allow_retry)
96
95
 
97
- select(sar, name, binds, prepare: prepared_statements && preparable, async: async && FutureResult::SelectAll)
96
+ select(sar, name, binds,
97
+ prepare: prepared_statements && preparable,
98
+ async: async && FutureResult::SelectAll,
99
+ allow_retry: allow_retry
100
+ )
98
101
  rescue ::RangeError
99
102
  ActiveRecord::Result.empty(async: async)
100
103
  end
@@ -112,7 +115,7 @@ module ActiveRecord
112
115
  internal_exec_query(sar, name, binds)
113
116
  end
114
117
 
115
- def internal_exec_query(arel, name = 'SAR', binds = [], prepare: false, async: false, allow_retry: false, materialize_transactions: true)
118
+ def internal_exec_query(arel, name = 'SAR', binds = [], prepare: false, async: false, allow_retry: false)
116
119
  sars = []
117
120
  multiple_requests = arel.is_a?(Arel::Collectors::Sunstone)
118
121
  type_casted_binds = binds#type_casted_binds(binds)
@@ -179,9 +182,9 @@ module ActiveRecord
179
182
  end
180
183
  end
181
184
 
182
- def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [])
185
+ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, binds = [], returning: nil)
183
186
  sar, binds = to_sar_and_binds(arel, binds)
184
- value = exec_insert(sar, name, binds, pk, sequence_name)
187
+ value = exec_insert(sar, name, binds, pk, sequence_name, returning: returning)
185
188
 
186
189
  return returning_column_values(value) unless returning.nil?
187
190
 
@@ -0,0 +1,19 @@
1
+ module ActiveRecord
2
+ module ConnectionAdapters
3
+ module Sunstone
4
+ module Quoting
5
+ extend ActiveSupport::Concern
6
+
7
+ module ClassMethods # :nodoc:
8
+
9
+ # Quotes column names for use in SQL queries.
10
+ def quote_column_name(name) # :nodoc:
11
+ name
12
+ end
13
+
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -3,6 +3,7 @@ require 'active_record/connection_adapters/abstract_adapter'
3
3
  require 'arel/nodes/relation'
4
4
  require 'arel/visitors/to_sql_extensions'
5
5
 
6
+ require 'active_record/connection_adapters/sunstone/quoting'
6
7
  require 'active_record/connection_adapters/sunstone/database_statements'
7
8
  require 'active_record/connection_adapters/sunstone/schema_statements'
8
9
  require 'active_record/connection_adapters/sunstone/schema_dumper'
@@ -15,19 +16,6 @@ require 'active_record/connection_adapters/sunstone/type/uuid'
15
16
  require 'active_record/connection_adapters/sunstone/type/json'
16
17
 
17
18
  module ActiveRecord
18
- module ConnectionHandling # :nodoc:
19
-
20
- def sunstone_adapter_class
21
- ConnectionAdapters::SunstoneAPIAdapter
22
- end
23
-
24
- # Establishes a connection to the database that's used by all Active Record
25
- # objects
26
- def sunstone_connection(config)
27
- sunstone_adapter_class.new(config)
28
- end
29
- end
30
-
31
19
  module ConnectionAdapters
32
20
  # The SunstoneAPI adapter.
33
21
  #
@@ -56,7 +44,7 @@ module ActiveRecord
56
44
  end
57
45
  end
58
46
 
59
- # include PostgreSQL::Quoting
47
+ include Sunstone::Quoting
60
48
  # include PostgreSQL::ReferentialIntegrity
61
49
  include Sunstone::SchemaStatements
62
50
  include Sunstone::DatabaseStatements
@@ -106,11 +94,6 @@ module ActiveRecord
106
94
  def active?
107
95
  @raw_connection&.active?
108
96
  end
109
-
110
- def load_type_map
111
- @type_map = Type::HashLookupTypeMap.new
112
- initialize_type_map(@type_map)
113
- end
114
97
 
115
98
  def reconnect
116
99
  super
@@ -169,6 +152,7 @@ module ActiveRecord
169
152
  end
170
153
 
171
154
  def lookup_cast_type_from_column(column) # :nodoc:
155
+ verify! if type_map.nil?
172
156
  cast_type = @type_map.lookup(column.sql_type, {
173
157
  limit: column.limit,
174
158
  precision: column.precision,
@@ -219,6 +203,8 @@ module ActiveRecord
219
203
  # Configures the encoding, verbosity, schema search path, and time zone of the connection.
220
204
  # This is called by #connect and should not be called manually.
221
205
  def configure_connection
206
+ super
207
+
222
208
  reload_type_map
223
209
  end
224
210
 
@@ -233,7 +219,9 @@ module ActiveRecord
233
219
  end
234
220
 
235
221
  private
236
-
222
+
223
+ attr_reader :type_map
224
+
237
225
  def initialize_type_map(m = nil)
238
226
  self.class.initialize_type_map(m || @type_map)
239
227
  end
@@ -203,7 +203,7 @@ module Sunstone
203
203
  close_connection = false
204
204
  @connection.request(request) do |response|
205
205
  if response['Deprecation-Notice']
206
- ActiveSupport::Deprecation.warn(response['Deprecation-Notice'])
206
+ ::ActiveRecord.deprecator.warn(response['Deprecation-Notice'])
207
207
  end
208
208
 
209
209
  validate_response_code(response)
@@ -1,3 +1,3 @@
1
1
  module Sunstone
2
- VERSION = '7.1.0.1'
2
+ VERSION = '7.2.0'
3
3
  end
data/lib/sunstone.rb CHANGED
@@ -39,17 +39,5 @@ require File.expand_path(File.join(__FILE__, '../../ext/arel/attributes/empty_re
39
39
  require File.expand_path(File.join(__FILE__, '../../ext/arel/nodes/select_statement'))
40
40
  require File.expand_path(File.join(__FILE__, '../../ext/active_record/finder_methods'))
41
41
 
42
- if ActiveRecord::VERSION::MAJOR == 6 && ActiveRecord::VERSION::MINOR == 1
43
- # Patch to allow Rails 6.1 pass url to adapter, all other versions work
44
- require 'active_record/database_configurations'
45
- class ActiveRecord::DatabaseConfigurations::UrlConfig
46
- private
47
- def build_url_hash
48
- if url.nil? || %w(jdbc: http: https:).any? { |protocol| url.start_with?(protocol) }
49
- { url: url }
50
- else
51
- ConnectionUrlResolver.new(url).to_hash
52
- end
53
- end
54
- end
55
- end
42
+
43
+ ActiveRecord::ConnectionAdapters.register("sunstone", "ActiveRecord::ConnectionAdapters::SunstoneAPIAdapter", "active_record/connection_adapters/sunstone_adapter")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sunstone
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.1.0.1
4
+ version: 7.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jon Bracy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-20 00:00:00.000000000 Z
11
+ date: 2024-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - ">="
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 6.5.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 6.5.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: webmock
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -184,14 +184,14 @@ dependencies:
184
184
  requirements:
185
185
  - - ">="
186
186
  - !ruby/object:Gem::Version
187
- version: 7.1.0
187
+ version: 7.2.0
188
188
  type: :development
189
189
  prerelease: false
190
190
  version_requirements: !ruby/object:Gem::Requirement
191
191
  requirements:
192
192
  - - ">="
193
193
  - !ruby/object:Gem::Version
194
- version: 7.1.0
194
+ version: 7.2.0
195
195
  - !ruby/object:Gem::Dependency
196
196
  name: msgpack
197
197
  requirement: !ruby/object:Gem::Requirement
@@ -226,14 +226,14 @@ dependencies:
226
226
  requirements:
227
227
  - - ">="
228
228
  - !ruby/object:Gem::Version
229
- version: 7.1.0
229
+ version: 7.2.0
230
230
  type: :runtime
231
231
  prerelease: false
232
232
  version_requirements: !ruby/object:Gem::Requirement
233
233
  requirements:
234
234
  - - ">="
235
235
  - !ruby/object:Gem::Version
236
- version: 7.1.0
236
+ version: 7.2.0
237
237
  - !ruby/object:Gem::Dependency
238
238
  name: arel-extensions
239
239
  requirement: !ruby/object:Gem::Requirement
@@ -288,6 +288,7 @@ files:
288
288
  - ext/arel/select_manager.rb
289
289
  - lib/active_record/connection_adapters/sunstone/column.rb
290
290
  - lib/active_record/connection_adapters/sunstone/database_statements.rb
291
+ - lib/active_record/connection_adapters/sunstone/quoting.rb
291
292
  - lib/active_record/connection_adapters/sunstone/schema_dumper.rb
292
293
  - lib/active_record/connection_adapters/sunstone/schema_statements.rb
293
294
  - lib/active_record/connection_adapters/sunstone/type/array.rb
@@ -323,7 +324,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
323
324
  - !ruby/object:Gem::Version
324
325
  version: '0'
325
326
  requirements: []
326
- rubygems_version: 3.4.13
327
+ rubygems_version: 3.5.11
327
328
  signing_key:
328
329
  specification_version: 4
329
330
  summary: A library for interacting with REST APIs