relation_to_struct 1.7.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +66 -0
- data/Appraisals +1 -6
- data/README.md +1 -1
- data/bin/setup +12 -0
- data/docker-compose.yml +8 -0
- data/gemfiles/rails_6_1.gemfile +0 -1
- data/gemfiles/rails_7_0.gemfile +0 -1
- data/gemfiles/{rails_5_0.gemfile → rails_7_1.gemfile} +1 -2
- data/lib/relation_to_struct/active_record_base_extension.rb +1 -5
- data/lib/relation_to_struct/active_record_connection_adapter_extension.rb +6 -6
- data/lib/relation_to_struct/active_record_relation_extension.rb +2 -7
- data/lib/relation_to_struct/version.rb +1 -1
- data/lib/relation_to_struct.rb +0 -3
- data/relation_to_struct.gemspec +3 -3
- data/spec/active_record_helper/setup.rb +3 -8
- metadata +21 -20
- data/gemfiles/rails_5_1.gemfile +0 -8
- data/gemfiles/rails_5_2.gemfile +0 -8
- data/gemfiles/rails_6_0.gemfile +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bb8b931d89b6d73791900b6e8103442856413d8bead16b0f006b28163765ae9
|
4
|
+
data.tar.gz: '01867db9481ad85af27892312f23a5f9ceb7687bc7b3232e1c952324be98ab81'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a9aa775119c2e6de109e000591b7dcdd149d5caccc5e3dc145cab69f7e22bc1d142a83bcbb47ccf55f0d2ea9109d44973a7ea6f87226ae46d300b6b6f87e49b
|
7
|
+
data.tar.gz: 701affeecbfbce06009babd6d48f6b98622f7de98d7fce6bb3a701c0587845940057ded3661c6e0574a7b7a46ff8003c0f0b7837705263f1377725dae44dd553
|
@@ -0,0 +1,66 @@
|
|
1
|
+
name: CI
|
2
|
+
on: [push, pull_request]
|
3
|
+
jobs:
|
4
|
+
test_postgres:
|
5
|
+
strategy:
|
6
|
+
matrix:
|
7
|
+
pg:
|
8
|
+
- 11
|
9
|
+
- 12
|
10
|
+
- 13
|
11
|
+
- 14
|
12
|
+
- 15
|
13
|
+
- 16
|
14
|
+
ruby:
|
15
|
+
- "3.0"
|
16
|
+
- "3.1"
|
17
|
+
- "3.2"
|
18
|
+
gemfile:
|
19
|
+
- rails_6_1
|
20
|
+
- rails_7_0
|
21
|
+
- rails_7_1
|
22
|
+
name: PostgreSQL ${{ matrix.pg }} - Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }}
|
23
|
+
runs-on: ubuntu-latest
|
24
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
25
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
26
|
+
ImageOS: ubuntu20
|
27
|
+
steps:
|
28
|
+
- uses: actions/checkout@v3
|
29
|
+
- name: Start the postgres container
|
30
|
+
run: docker-compose up -d
|
31
|
+
env:
|
32
|
+
PGVERSION: ${{ matrix.pg }}
|
33
|
+
- name: Setup Ruby using .ruby-version file
|
34
|
+
uses: ruby/setup-ruby@v1
|
35
|
+
with:
|
36
|
+
ruby-version: ${{ matrix.ruby }}
|
37
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
38
|
+
- run: bundle exec rake spec
|
39
|
+
env:
|
40
|
+
DATABASE: postgresql
|
41
|
+
test_sqlite:
|
42
|
+
strategy:
|
43
|
+
matrix:
|
44
|
+
ruby:
|
45
|
+
- "3.0"
|
46
|
+
- "3.1"
|
47
|
+
- "3.2"
|
48
|
+
gemfile:
|
49
|
+
- rails_6_1
|
50
|
+
- rails_7_0
|
51
|
+
- rails_7_1
|
52
|
+
name: SQLite - Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }}
|
53
|
+
runs-on: ubuntu-latest
|
54
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
55
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
56
|
+
ImageOS: ubuntu20
|
57
|
+
steps:
|
58
|
+
- uses: actions/checkout@v3
|
59
|
+
- name: Setup Ruby using .ruby-version file
|
60
|
+
uses: ruby/setup-ruby@v1
|
61
|
+
with:
|
62
|
+
ruby-version: ${{ matrix.ruby }}
|
63
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
64
|
+
- run: bundle exec rake spec
|
65
|
+
env:
|
66
|
+
DATABASE: sqlite
|
data/Appraisals
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
%w(
|
1
|
+
%w(6.1 7.0 7.1).each do |version|
|
2
2
|
appraise "rails-#{version.gsub(/\./, "-")}" do
|
3
3
|
gem "rails", "~> #{version}.0"
|
4
|
-
if Gem::Version.new(version) >= Gem::Version.new("6.0.0")
|
5
|
-
gem "sqlite3", "~> 1.4.0"
|
6
|
-
else
|
7
|
-
gem "sqlite3", "~> 1.3.0"
|
8
|
-
end
|
9
4
|
end
|
10
5
|
end
|
data/README.md
CHANGED
@@ -110,4 +110,4 @@ For this reason, **all methods added to `ActiveRecord::Base` explicitly disable
|
|
110
110
|
|
111
111
|
1. Bump version in `lib/relation_to_struct/version.rb` and commit.
|
112
112
|
2. Run `rake build` to build the `*.gem` file.
|
113
|
-
3. Run `rake release` to publish the gem to Rubygems.
|
113
|
+
3. Run `rake release` to publish the gem to Rubygems. Note: if while releasing the gem you get the error ``Your rubygems.org credentials aren't set. Run `gem push` to set them.`` you can more simply run `gem signin`.
|
data/bin/setup
ADDED
data/docker-compose.yml
ADDED
data/gemfiles/rails_6_1.gemfile
CHANGED
data/gemfiles/rails_7_0.gemfile
CHANGED
@@ -1,9 +1,5 @@
|
|
1
1
|
module RelationToStruct::ActiveRecordBaseExtension
|
2
2
|
module ClassMethods
|
3
|
-
def _sanitize_sql_for_relation_to_struct(sql)
|
4
|
-
sanitized_sql = ActiveRecord::VERSION::MAJOR >= 5 ? sanitize_sql(sql) : sanitize_sql(sql, nil)
|
5
|
-
end
|
6
|
-
|
7
3
|
delegate(
|
8
4
|
:structs_from_sql,
|
9
5
|
:pluck_from_sql,
|
@@ -15,4 +11,4 @@ module RelationToStruct::ActiveRecordBaseExtension
|
|
15
11
|
end
|
16
12
|
end
|
17
13
|
|
18
|
-
::ActiveRecord::Base.singleton_class.
|
14
|
+
::ActiveRecord::Base.singleton_class.prepend(RelationToStruct::ActiveRecordBaseExtension::ClassMethods)
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module RelationToStruct::ActiveRecordConnectionAdapterExtension
|
2
2
|
def structs_from_sql(struct_class, sql, binds=[])
|
3
|
-
sanitized_sql = ActiveRecord::Base.
|
3
|
+
sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
|
4
4
|
result = ActiveRecord::Base.uncached do
|
5
5
|
select_all(sanitized_sql, "Structs SQL Load", binds)
|
6
6
|
end
|
@@ -25,7 +25,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def pluck_from_sql(sql, binds=[])
|
28
|
-
sanitized_sql = ActiveRecord::Base.
|
28
|
+
sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
|
29
29
|
result = ActiveRecord::Base.uncached do
|
30
30
|
select_all(sanitized_sql, "Pluck SQL Load", binds)
|
31
31
|
end
|
@@ -33,7 +33,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def value_from_sql(sql, binds=[])
|
36
|
-
sanitized_sql = ActiveRecord::Base.
|
36
|
+
sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
|
37
37
|
result = ActiveRecord::Base.uncached do
|
38
38
|
select_all(sanitized_sql, "Value SQL Load", binds)
|
39
39
|
end
|
@@ -51,7 +51,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def tuple_from_sql(sql, binds=[])
|
54
|
-
sanitized_sql = ActiveRecord::Base.
|
54
|
+
sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
|
55
55
|
result = ActiveRecord::Base.uncached do
|
56
56
|
select_all(sanitized_sql, "Value SQL Load", binds)
|
57
57
|
end
|
@@ -68,7 +68,7 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
|
|
68
68
|
end
|
69
69
|
|
70
70
|
def run_sql(sql, binds=[])
|
71
|
-
sanitized_sql = ActiveRecord::Base.
|
71
|
+
sanitized_sql = ActiveRecord::Base.sanitize_sql(sql)
|
72
72
|
# We don't need to build a result set unnecessarily; using
|
73
73
|
# interface this also ensures we're clearing the result set
|
74
74
|
# for manually memory managed object (e.g., when using the
|
@@ -77,4 +77,4 @@ module RelationToStruct::ActiveRecordConnectionAdapterExtension
|
|
77
77
|
end
|
78
78
|
end
|
79
79
|
|
80
|
-
::ActiveRecord::ConnectionAdapters::AbstractAdapter.
|
80
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(RelationToStruct::ActiveRecordConnectionAdapterExtension)
|
@@ -6,12 +6,7 @@ module RelationToStruct::ActiveRecordRelationExtension
|
|
6
6
|
|
7
7
|
# See the definition of #pluck in:
|
8
8
|
# activerecord/lib/active_record/relation/calculations.rb
|
9
|
-
result =
|
10
|
-
if ActiveRecord::VERSION::MAJOR == 5 && ActiveRecord::VERSION::MINOR < 2
|
11
|
-
result = klass.connection.select_all(relation.arel, nil, bound_attributes)
|
12
|
-
else
|
13
|
-
result = klass.connection.select_all(relation.arel)
|
14
|
-
end
|
9
|
+
result = klass.connection.select_all(relation.arel)
|
15
10
|
|
16
11
|
if result.columns.size != struct_class.members.size
|
17
12
|
raise ArgumentError, 'Expected struct fields and columns lengths to be equal'
|
@@ -35,4 +30,4 @@ module RelationToStruct::ActiveRecordRelationExtension
|
|
35
30
|
end
|
36
31
|
end
|
37
32
|
|
38
|
-
::ActiveRecord::Relation.
|
33
|
+
::ActiveRecord::Relation.prepend(RelationToStruct::ActiveRecordRelationExtension)
|
data/lib/relation_to_struct.rb
CHANGED
data/relation_to_struct.gemspec
CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |spec|
|
|
21
21
|
spec.add_development_dependency "appraisal", ">= 2.1"
|
22
22
|
spec.add_development_dependency "bundler", ">= 1.7"
|
23
23
|
spec.add_development_dependency "rake", ">= 10.0"
|
24
|
-
spec.add_development_dependency "sqlite3", ">= 1.
|
24
|
+
spec.add_development_dependency "sqlite3", ">= 1.4"
|
25
25
|
spec.add_development_dependency "rspec", ">= 3.2"
|
26
26
|
spec.add_development_dependency "pry-byebug"
|
27
27
|
spec.add_development_dependency "pg"
|
28
28
|
|
29
|
-
spec.add_dependency "activerecord", ">=
|
30
|
-
spec.add_dependency "activesupport", ">=
|
29
|
+
spec.add_dependency "activerecord", ">= 6.1", "< 7.2"
|
30
|
+
spec.add_dependency "activesupport", ">= 6.1", "< 7.2"
|
31
31
|
end
|
@@ -4,8 +4,8 @@ ActiveRecord::Base.configurations = {
|
|
4
4
|
"host" => 'localhost',
|
5
5
|
"database" => 'relation_to_struct_tests',
|
6
6
|
"encoding" => 'utf8',
|
7
|
-
"username" => ENV["
|
8
|
-
"password" => ENV["
|
7
|
+
"username" => ENV["PGUSER"] || 'postgres',
|
8
|
+
"password" => ENV["PGPASSWORD"] || 'postgres',
|
9
9
|
},
|
10
10
|
"sqlite" => {
|
11
11
|
"adapter" => "sqlite3",
|
@@ -14,12 +14,7 @@ ActiveRecord::Base.configurations = {
|
|
14
14
|
}
|
15
15
|
|
16
16
|
env = ENV['DATABASE'] ||= 'sqlite'
|
17
|
-
config =
|
18
|
-
if ActiveRecord::VERSION::MAJOR < 7
|
19
|
-
ActiveRecord::Base.configurations[env]
|
20
|
-
else
|
21
|
-
ActiveRecord::Base.configurations.configs_for(env_name: env).first
|
22
|
-
end
|
17
|
+
config = ActiveRecord::Base.configurations.configs_for(env_name: env).first
|
23
18
|
|
24
19
|
case env
|
25
20
|
when 'postgresql'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relation_to_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Coleman
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '1.
|
61
|
+
version: '1.4'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '1.
|
68
|
+
version: '1.4'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,47 +114,49 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '6.1'
|
118
118
|
- - "<"
|
119
119
|
- !ruby/object:Gem::Version
|
120
|
-
version: '7.
|
120
|
+
version: '7.2'
|
121
121
|
type: :runtime
|
122
122
|
prerelease: false
|
123
123
|
version_requirements: !ruby/object:Gem::Requirement
|
124
124
|
requirements:
|
125
125
|
- - ">="
|
126
126
|
- !ruby/object:Gem::Version
|
127
|
-
version: '
|
127
|
+
version: '6.1'
|
128
128
|
- - "<"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '7.
|
130
|
+
version: '7.2'
|
131
131
|
- !ruby/object:Gem::Dependency
|
132
132
|
name: activesupport
|
133
133
|
requirement: !ruby/object:Gem::Requirement
|
134
134
|
requirements:
|
135
135
|
- - ">="
|
136
136
|
- !ruby/object:Gem::Version
|
137
|
-
version: '
|
137
|
+
version: '6.1'
|
138
138
|
- - "<"
|
139
139
|
- !ruby/object:Gem::Version
|
140
|
-
version: '7.
|
140
|
+
version: '7.2'
|
141
141
|
type: :runtime
|
142
142
|
prerelease: false
|
143
143
|
version_requirements: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
145
|
- - ">="
|
146
146
|
- !ruby/object:Gem::Version
|
147
|
-
version: '
|
147
|
+
version: '6.1'
|
148
148
|
- - "<"
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version: '7.
|
150
|
+
version: '7.2'
|
151
151
|
description: ''
|
152
152
|
email:
|
153
153
|
- jtc331@gmail.com
|
154
|
-
executables:
|
154
|
+
executables:
|
155
|
+
- setup
|
155
156
|
extensions: []
|
156
157
|
extra_rdoc_files: []
|
157
158
|
files:
|
159
|
+
- ".github/workflows/ci.yml"
|
158
160
|
- ".gitignore"
|
159
161
|
- ".rspec"
|
160
162
|
- Appraisals
|
@@ -162,12 +164,11 @@ files:
|
|
162
164
|
- LICENSE.txt
|
163
165
|
- README.md
|
164
166
|
- Rakefile
|
165
|
-
-
|
166
|
-
-
|
167
|
-
- gemfiles/rails_5_2.gemfile
|
168
|
-
- gemfiles/rails_6_0.gemfile
|
167
|
+
- bin/setup
|
168
|
+
- docker-compose.yml
|
169
169
|
- gemfiles/rails_6_1.gemfile
|
170
170
|
- gemfiles/rails_7_0.gemfile
|
171
|
+
- gemfiles/rails_7_1.gemfile
|
171
172
|
- lib/relation_to_struct.rb
|
172
173
|
- lib/relation_to_struct/active_record_base_extension.rb
|
173
174
|
- lib/relation_to_struct/active_record_connection_adapter_extension.rb
|
@@ -187,7 +188,7 @@ homepage: ''
|
|
187
188
|
licenses:
|
188
189
|
- MIT
|
189
190
|
metadata: {}
|
190
|
-
post_install_message:
|
191
|
+
post_install_message:
|
191
192
|
rdoc_options: []
|
192
193
|
require_paths:
|
193
194
|
- lib
|
@@ -203,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
203
204
|
version: '0'
|
204
205
|
requirements: []
|
205
206
|
rubygems_version: 3.1.6
|
206
|
-
signing_key:
|
207
|
+
signing_key:
|
207
208
|
specification_version: 4
|
208
209
|
summary: Return struct results from ActiveRecord relation queries
|
209
210
|
test_files:
|
data/gemfiles/rails_5_1.gemfile
DELETED
data/gemfiles/rails_5_2.gemfile
DELETED