relation_to_struct 1.7.0 → 1.9.1
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 +64 -0
- data/.gitignore +0 -1
- data/.pryrc +21 -0
- data/.ruby-version +1 -0
- data/Appraisals +1 -6
- data/README.md +9 -8
- 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/gemfiles/{rails_5_1.gemfile → rails_7_2.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 +4 -4
- data/spec/active_record_helper/setup.rb +3 -8
- data/spec/spec_helper.rb +0 -1
- metadata +26 -22
- 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: 6ebd7741a088cfbc209a2013e1c6feac68233029bbdb72d8141ba3f711414c8b
|
4
|
+
data.tar.gz: 668edbe5050f12f20dab89ea891e062a4f8ab7b2e11775dd57162d4a58f94b80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d58bc5eab67aa7ea28efed4d48365216dcb50f5c48b40b97056dc664ed64da33643f2e5a057ac4ea4c54c4074f81980ef1fa244ae4c4e1ea4d03346da4481bbd
|
7
|
+
data.tar.gz: 1fdaef138830916143a5731893e274aa0d9a3769821829b848074f39917d1d782804b5c78baf92e5570d396f89463c7e883ed737d6c3a466c2615fd0003b1735
|
@@ -0,0 +1,64 @@
|
|
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.1"
|
16
|
+
- "3.2"
|
17
|
+
gemfile:
|
18
|
+
- rails_6_1
|
19
|
+
- rails_7_0
|
20
|
+
- rails_7_1
|
21
|
+
- rails_7_2
|
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
|
+
steps:
|
27
|
+
- uses: actions/checkout@v3
|
28
|
+
- name: Start the postgres container
|
29
|
+
run: docker compose up -d
|
30
|
+
env:
|
31
|
+
PGVERSION: ${{ matrix.pg }}
|
32
|
+
- name: Setup Ruby using .ruby-version file
|
33
|
+
uses: ruby/setup-ruby@v1
|
34
|
+
with:
|
35
|
+
ruby-version: ${{ matrix.ruby }}
|
36
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
+
- run: bundle exec rake spec
|
38
|
+
env:
|
39
|
+
DATABASE: postgresql
|
40
|
+
test_sqlite:
|
41
|
+
strategy:
|
42
|
+
matrix:
|
43
|
+
ruby:
|
44
|
+
- "3.1"
|
45
|
+
- "3.2"
|
46
|
+
gemfile:
|
47
|
+
- rails_6_1
|
48
|
+
- rails_7_0
|
49
|
+
- rails_7_1
|
50
|
+
- rails_7_2
|
51
|
+
name: SQLite - Ruby ${{ matrix.ruby }} - ${{ matrix.gemfile }}
|
52
|
+
runs-on: ubuntu-latest
|
53
|
+
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
54
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
|
55
|
+
steps:
|
56
|
+
- uses: actions/checkout@v3
|
57
|
+
- name: Setup Ruby using .ruby-version file
|
58
|
+
uses: ruby/setup-ruby@v1
|
59
|
+
with:
|
60
|
+
ruby-version: ${{ matrix.ruby }}
|
61
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
62
|
+
- run: bundle exec rake spec
|
63
|
+
env:
|
64
|
+
DATABASE: sqlite
|
data/.gitignore
CHANGED
data/.pryrc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "pry-byebug"
|
2
|
+
|
3
|
+
Pry.commands.alias_command 'c', 'continue'
|
4
|
+
Pry.commands.alias_command 's', 'step'
|
5
|
+
Pry.commands.alias_command 'n', 'next'
|
6
|
+
Pry.commands.alias_command 'f', 'finish'
|
7
|
+
|
8
|
+
# https://github.com/pry/pry/issues/1275#issuecomment-131969510
|
9
|
+
# Prevent issue where text input does not display on screen in container after typing Ctrl-C in a pry repl
|
10
|
+
at_exit do
|
11
|
+
exit!(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
trap('INT') do
|
15
|
+
begin
|
16
|
+
Pry.run_command "continue", :show_output => true, :target => Pry.current
|
17
|
+
rescue
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
# End pry Ctrl-C workaround
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.2
|
data/Appraisals
CHANGED
@@ -1,10 +1,5 @@
|
|
1
|
-
%w(
|
1
|
+
%w(6.1 7.0 7.1 7.2).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
@@ -1,6 +1,6 @@
|
|
1
1
|
# RelationToStruct
|
2
2
|
|
3
|
-
[![Build Status](https://
|
3
|
+
[![Build Status](https://github.com/jcoleman/relation_to_struct/actions/workflows/ci.yml/badge.svg)](https://github.com/jcoleman/relation_to_struct/actions/workflows/ci.yml?query=branch%3Amaster+)
|
4
4
|
|
5
5
|
When one needs to use ActiveRecord to fetch specific values (whether subset columns of a model or arbitrary calculated columns), it's desirable to avoid the overhead of model instances and any associated callbacks.
|
6
6
|
|
@@ -100,14 +100,15 @@ For this reason, **all methods added to `ActiveRecord::Base` explicitly disable
|
|
100
100
|
## Contributing
|
101
101
|
|
102
102
|
1. Fork it ( https://github.com/jcoleman/relation_to_struct/fork )
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
1. Create your feature branch (`git checkout -b my-new-feature`)
|
104
|
+
1. Install gems and spin up a PostgreSQL container (`bin/setup`)
|
105
|
+
1. Test your changes (`bundle exec appraisal rake && DATABASE=postgresql bundle exec appraisal rake`)
|
106
|
+
1. Commit your changes (`git commit -am 'Add some feature'`)
|
107
|
+
1. Push to the branch (`git push origin my-new-feature`)
|
108
|
+
1. Create a new Pull Request
|
108
109
|
|
109
110
|
## Releasing
|
110
111
|
|
111
112
|
1. Bump version in `lib/relation_to_struct/version.rb` and commit.
|
112
|
-
|
113
|
-
|
113
|
+
1. Run `rake build` to build the `*.gem` file.
|
114
|
+
1. 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
@@ -18,14 +18,14 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "appraisal", ">= 2.
|
21
|
+
spec.add_development_dependency "appraisal", ">= 2.5"
|
22
22
|
spec.add_development_dependency "bundler", ">= 1.7"
|
23
23
|
spec.add_development_dependency "rake", ">= 10.0"
|
24
|
-
spec.add_development_dependency "sqlite3", "
|
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.3"
|
30
|
+
spec.add_dependency "activesupport", ">= 6.1", "< 7.3"
|
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'
|
data/spec/spec_helper.rb
CHANGED
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Coleman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '2.
|
19
|
+
version: '2.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '2.
|
26
|
+
version: '2.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
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,60 +114,64 @@ 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.3'
|
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.3'
|
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.3'
|
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.3'
|
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"
|
161
|
+
- ".pryrc"
|
159
162
|
- ".rspec"
|
163
|
+
- ".ruby-version"
|
160
164
|
- Appraisals
|
161
165
|
- Gemfile
|
162
166
|
- LICENSE.txt
|
163
167
|
- README.md
|
164
168
|
- Rakefile
|
165
|
-
-
|
166
|
-
-
|
167
|
-
- gemfiles/rails_5_2.gemfile
|
168
|
-
- gemfiles/rails_6_0.gemfile
|
169
|
+
- bin/setup
|
170
|
+
- docker-compose.yml
|
169
171
|
- gemfiles/rails_6_1.gemfile
|
170
172
|
- gemfiles/rails_7_0.gemfile
|
173
|
+
- gemfiles/rails_7_1.gemfile
|
174
|
+
- gemfiles/rails_7_2.gemfile
|
171
175
|
- lib/relation_to_struct.rb
|
172
176
|
- lib/relation_to_struct/active_record_base_extension.rb
|
173
177
|
- lib/relation_to_struct/active_record_connection_adapter_extension.rb
|
@@ -202,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
202
206
|
- !ruby/object:Gem::Version
|
203
207
|
version: '0'
|
204
208
|
requirements: []
|
205
|
-
rubygems_version: 3.
|
209
|
+
rubygems_version: 3.5.9
|
206
210
|
signing_key:
|
207
211
|
specification_version: 4
|
208
212
|
summary: Return struct results from ActiveRecord relation queries
|
data/gemfiles/rails_5_2.gemfile
DELETED