query_relation 0.1.1 → 0.2.0
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 +5 -5
- data/.codeclimate.yml +16 -0
- data/.github/workflows/ci.yaml +37 -0
- data/.rspec +1 -1
- data/.rubocop.yml +4 -0
- data/.rubocop_cc.yml +4 -0
- data/.rubocop_local.yml +0 -0
- data/.whitesource +3 -0
- data/CHANGELOG.md +16 -3
- data/README.md +7 -0
- data/lib/query_relation/queryable.rb +2 -0
- data/lib/query_relation/version.rb +1 -1
- data/lib/query_relation.rb +79 -30
- data/query_relation.gemspec +5 -6
- data/renovate.json +5 -0
- metadata +34 -32
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e8615131100966dea784b0fb003b5ef481b2ccf078c5fc7fa58f476f3bfb00b
|
4
|
+
data.tar.gz: cf5ecd6368a52f13868f3fa9f96fbb803609a56cd9b388df5fae8c10b565aebe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a27749c6b342aa7f7a103e88474cc5fc74bae35ab45b2da1c73aaf8e40e328e570305fc138a17b11e8549c299351955f99abe35e4bb9c7881e2e1ea0777ce3d9
|
7
|
+
data.tar.gz: a392e0251959c7573342e10fc277b2c3720c580ae61f615e3b65768f75ed59ad83e22673aab8a99787d46758715dc4142aeccb9b1314616390cef838a72cbad4
|
data/.codeclimate.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
prepare:
|
2
|
+
fetch:
|
3
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_base.yml
|
4
|
+
path: ".rubocop_base.yml"
|
5
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/.rubocop_cc_base.yml
|
6
|
+
path: ".rubocop_cc_base.yml"
|
7
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/base.yml
|
8
|
+
path: styles/base.yml
|
9
|
+
- url: https://raw.githubusercontent.com/ManageIQ/manageiq-style/master/styles/cc_base.yml
|
10
|
+
path: styles/cc_base.yml
|
11
|
+
plugins:
|
12
|
+
rubocop:
|
13
|
+
enabled: true
|
14
|
+
config: ".rubocop_cc.yml"
|
15
|
+
channel: rubocop-1-56-3
|
16
|
+
version: '2'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
---
|
2
|
+
name: CI
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
pull_request:
|
6
|
+
schedule:
|
7
|
+
- cron: 0 0 * * 0
|
8
|
+
jobs:
|
9
|
+
ci:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby-version:
|
14
|
+
- '2.5'
|
15
|
+
- '2.6'
|
16
|
+
- '2.7'
|
17
|
+
- '3.0'
|
18
|
+
- '3.1'
|
19
|
+
- '3.2'
|
20
|
+
- '3.3'
|
21
|
+
- '3.4'
|
22
|
+
env:
|
23
|
+
CC_TEST_REPORTER_ID: "${{ secrets.CC_TEST_REPORTER_ID }}"
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v5
|
26
|
+
- name: Set up Ruby
|
27
|
+
uses: ruby/setup-ruby@v1
|
28
|
+
with:
|
29
|
+
ruby-version: "${{ matrix.ruby-version }}"
|
30
|
+
bundler-cache: true
|
31
|
+
timeout-minutes: 30
|
32
|
+
- name: Run tests
|
33
|
+
run: bundle exec rake
|
34
|
+
- name: Report code coverage
|
35
|
+
if: ${{ github.ref == 'refs/heads/master' && matrix.ruby-version == '3.4' }}
|
36
|
+
continue-on-error: true
|
37
|
+
uses: paambaati/codeclimate-action@v9
|
data/.rspec
CHANGED
data/.rubocop.yml
ADDED
data/.rubocop_cc.yml
ADDED
data/.rubocop_local.yml
ADDED
File without changes
|
data/.whitesource
ADDED
data/CHANGELOG.md
CHANGED
@@ -6,10 +6,23 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [0.
|
9
|
+
## [0.2.0] - 2025-10-07
|
10
|
+
### Fixed
|
11
|
+
- `Model#pluck` now passes `:select` [#34](https://github.com/ManageIQ/query_relation/pull/34)
|
12
|
+
|
13
|
+
### Added
|
14
|
+
- Added support for Ruby 2.5-3.4 [#44](https://github.com/ManageIQ/query_relation/pull/44) and others
|
15
|
+
- Support for `Model.to_a` [#34](https://github.com/ManageIQ/query_relation/pull/34)
|
16
|
+
- Backwards compatibility between references/includes and eager_load/preload [#43](https://github.com/ManageIQ/query_relation/pull/43)
|
17
|
+
|
18
|
+
### Changed
|
19
|
+
- Dropped dependencies: more_core_extensions and active_support. [#31](https://github.com/ManageIQ/query_relation/pull/31)
|
20
|
+
|
21
|
+
## [0.1.1] - 2016-11-17
|
10
22
|
### Added
|
11
23
|
- Add CHANGELOG.md
|
12
24
|
- Update README with usage instructions.
|
13
25
|
|
14
|
-
[Unreleased]: https://github.com/ManageIQ/query_relation/compare/v0.
|
15
|
-
[0.
|
26
|
+
[Unreleased]: https://github.com/ManageIQ/query_relation/compare/v0.2.0...HEAD
|
27
|
+
[0.2.0]: https://github.com/ManageIQ/query_relation/compare/v0.1.1...v0.2.0
|
28
|
+
[0.1.1]: https://github.com/ManageIQ/query_relation/compare/v0.1.0...v0.1.1
|
data/README.md
CHANGED
@@ -2,6 +2,13 @@
|
|
2
2
|
|
3
3
|
Provides an ActiveRecord::Relation-like DSL to non-SQL backends
|
4
4
|
|
5
|
+
[](http://badge.fury.io/rb/query_relation)
|
6
|
+
[](https://github.com/ManageIQ/query_relation/actions/workflows/ci.yaml)
|
7
|
+
[](https://codeclimate.com/github/ManageIQ/query_relation)
|
8
|
+
[](https://codeclimate.com/github/ManageIQ/query_relation/coverage)
|
9
|
+
|
10
|
+
[](https://gitter.im/ManageIQ/query_relation?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
11
|
+
|
5
12
|
## Installation
|
6
13
|
|
7
14
|
Add this line to your application's Gemfile:
|
data/lib/query_relation.rb
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
require 'query_relation/version'
|
2
2
|
require 'query_relation/queryable'
|
3
3
|
|
4
|
-
require 'active_support/core_ext/array/wrap'
|
5
|
-
require 'active_support/core_ext/enumerable'
|
6
|
-
require 'active_support/core_ext/object/blank'
|
7
|
-
|
8
|
-
require 'more_core_extensions/core_ext/hash/deletes'
|
9
|
-
|
10
4
|
require 'forwardable'
|
11
5
|
|
12
6
|
class QueryRelation
|
@@ -18,20 +12,22 @@ class QueryRelation
|
|
18
12
|
# - [ ] bind
|
19
13
|
# - [ ] create_with
|
20
14
|
# - [ ] distinct
|
21
|
-
# - [
|
15
|
+
# - [X] eager_load (partial - leveraging references)
|
22
16
|
# - [X] except ? - is this not defined in the interface?
|
23
17
|
# - [ ] extending
|
24
18
|
# - [ ] from
|
25
19
|
# - [X] group
|
26
20
|
# - [ ] ~~having~~ - NO
|
27
21
|
# - [X] includes (partial)
|
28
|
-
# - [
|
22
|
+
# - [X] joins (partial - references includes)
|
23
|
+
# - [ ] left_joins
|
24
|
+
# - [ ] left_outer_joins
|
29
25
|
# - [X] limit
|
30
26
|
# - [ ] lock
|
31
27
|
# - [.] none
|
32
28
|
# - [X] offset
|
33
29
|
# - [X] order (partial)
|
34
|
-
# - [
|
30
|
+
# - [X] preload (partial - leveraging includes)
|
35
31
|
# - [ ] readonly
|
36
32
|
# - [X] references (partial)
|
37
33
|
# - [X] reorder
|
@@ -53,14 +49,15 @@ class QueryRelation
|
|
53
49
|
val = val.first if val.size == 1 && val.first.kind_of?(Hash)
|
54
50
|
dup.tap do |r|
|
55
51
|
old_where = r.options[:where]
|
56
|
-
if val.
|
52
|
+
if val.nil? || val.empty?
|
57
53
|
# nop
|
58
|
-
elsif old_where.
|
54
|
+
elsif old_where.nil? || old_where.empty?
|
59
55
|
r.options[:where] = val
|
60
56
|
elsif old_where.kind_of?(Hash) && val.kind_of?(Hash)
|
57
|
+
old_where = r.options[:where] = r.options[:where].dup
|
61
58
|
val.each_pair do |key, value|
|
62
59
|
old_where[key] = if old_where[key]
|
63
|
-
Array
|
60
|
+
Array(old_where[key]) + Array(value)
|
64
61
|
else
|
65
62
|
value
|
66
63
|
end
|
@@ -72,14 +69,32 @@ class QueryRelation
|
|
72
69
|
end
|
73
70
|
end
|
74
71
|
|
72
|
+
def where_values
|
73
|
+
options[:where]
|
74
|
+
end
|
75
|
+
|
75
76
|
def includes(*args)
|
76
77
|
append_hash_array_arg :includes, {}, *args
|
77
78
|
end
|
78
79
|
|
80
|
+
def includes_values
|
81
|
+
options[:includes] || []
|
82
|
+
end
|
83
|
+
|
84
|
+
alias preload includes
|
85
|
+
alias preload_values includes_values
|
86
|
+
|
79
87
|
def references(*args)
|
80
88
|
append_hash_array_arg :references, {}, *args
|
81
89
|
end
|
82
90
|
|
91
|
+
def references_values
|
92
|
+
options[:references] || []
|
93
|
+
end
|
94
|
+
|
95
|
+
alias joins references
|
96
|
+
|
97
|
+
# @param val [Integer] maximum number of rows to bring back
|
83
98
|
def limit(val)
|
84
99
|
assign_arg :limit, val
|
85
100
|
end
|
@@ -88,29 +103,35 @@ class QueryRelation
|
|
88
103
|
options[:limit]
|
89
104
|
end
|
90
105
|
|
91
|
-
|
92
|
-
|
106
|
+
# @param columns [Array<Symbol>, Symbol] columns for order
|
107
|
+
def order(*columns)
|
108
|
+
append_hash_array_arg :order, "ASC", *columns
|
93
109
|
end
|
94
110
|
|
95
111
|
def order_values
|
96
112
|
options[:order] || []
|
97
113
|
end
|
98
114
|
|
99
|
-
|
100
|
-
|
115
|
+
# @param columns [Array<Symbol>, Symbol] columns for order, replacing original
|
116
|
+
def group(*columns)
|
117
|
+
append_hash_arg :group, *columns
|
101
118
|
end
|
102
119
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
120
|
+
# @param columns [Array<Symbol>, Symbol] columns for order, replacing original
|
121
|
+
def reorder(*columns)
|
122
|
+
columns = columns.flatten.compact
|
123
|
+
if columns.first.kind_of?(Hash)
|
124
|
+
raise ArgumentError, "Need to support #{__callee__}(#{columns.class.name})"
|
107
125
|
end
|
108
126
|
|
109
|
-
|
110
|
-
r.options[:order] = val
|
111
|
-
end
|
127
|
+
assign_arg(:order, columns)
|
112
128
|
end
|
113
129
|
|
130
|
+
# similar to references, except takes typical hash and doesn't require includes entry
|
131
|
+
alias eager_load references
|
132
|
+
alias eager_load_values references_values
|
133
|
+
|
134
|
+
# @param val [Array<Symbol>, Symbol] attributes to remove from the query
|
114
135
|
def except(*val)
|
115
136
|
dup.tap do |r|
|
116
137
|
val.flatten.compact.each do |key|
|
@@ -119,6 +140,7 @@ class QueryRelation
|
|
119
140
|
end
|
120
141
|
end
|
121
142
|
|
143
|
+
# @param val [Array<Symbol>, Symbol] attributes to remove from the query
|
122
144
|
# similar to except. difference being this persists across merges
|
123
145
|
def unscope(*val)
|
124
146
|
dup.tap do |r|
|
@@ -128,6 +150,7 @@ class QueryRelation
|
|
128
150
|
end
|
129
151
|
end
|
130
152
|
|
153
|
+
# @param val [Integer] offset
|
131
154
|
def offset(val)
|
132
155
|
assign_arg :offset, val
|
133
156
|
end
|
@@ -136,9 +159,23 @@ class QueryRelation
|
|
136
159
|
options[:offset]
|
137
160
|
end
|
138
161
|
|
139
|
-
# @param
|
140
|
-
def select(*
|
141
|
-
append_hash_arg :select, *
|
162
|
+
# @param columns [Array<Sting, Symbol>, String, Symbol] columns to bring back
|
163
|
+
def select(*columns)
|
164
|
+
append_hash_arg :select, *columns
|
165
|
+
end
|
166
|
+
|
167
|
+
# @param columns [Array<Sting,Symbol>,String, Symbol] columns to bring back
|
168
|
+
def pluck(*columns)
|
169
|
+
columns = columns.flatten.compact
|
170
|
+
|
171
|
+
val = assign_arg(:select, columns).to_a
|
172
|
+
|
173
|
+
if columns.size == 1
|
174
|
+
column = columns.first
|
175
|
+
val.map { |row| row[column] }
|
176
|
+
else
|
177
|
+
val.map { |row| columns.map { |col| row[col] } }
|
178
|
+
end
|
142
179
|
end
|
143
180
|
|
144
181
|
def to_a
|
@@ -155,7 +192,19 @@ class QueryRelation
|
|
155
192
|
to_a.size
|
156
193
|
end
|
157
194
|
|
158
|
-
def_delegators :to_a, :size, :length, :take, :each, :empty
|
195
|
+
def_delegators :to_a, :size, :length, :take, :each, :empty?
|
196
|
+
|
197
|
+
def presence
|
198
|
+
to_a if present?
|
199
|
+
end
|
200
|
+
|
201
|
+
def blank?
|
202
|
+
to_a.nil? || to_a.empty?
|
203
|
+
end
|
204
|
+
|
205
|
+
def present?
|
206
|
+
!blank?
|
207
|
+
end
|
159
208
|
|
160
209
|
# TODO: support arguments
|
161
210
|
def first
|
@@ -178,7 +227,7 @@ class QueryRelation
|
|
178
227
|
end
|
179
228
|
|
180
229
|
def call_query_method(mode)
|
181
|
-
@target.call(mode, options.
|
230
|
+
@target.call(mode, options.delete_if { |_n, v| v.nil? || (v.respond_to?(:empty?) && v.empty?) })
|
182
231
|
end
|
183
232
|
|
184
233
|
def append_hash_arg(symbol, *val)
|
@@ -203,9 +252,9 @@ class QueryRelation
|
|
203
252
|
# @param b [Array, Hash]
|
204
253
|
# @param default default value for conversion to a hash. e.g.: {} or "ASC"
|
205
254
|
def merge_hash_or_array(a, b, default = {})
|
206
|
-
if a.
|
255
|
+
if a.nil? || a.empty?
|
207
256
|
b
|
208
|
-
elsif b.
|
257
|
+
elsif b.nil? || b.empty?
|
209
258
|
a
|
210
259
|
elsif a.kind_of?(Array) && b.kind_of?(Array)
|
211
260
|
a + b
|
data/query_relation.gemspec
CHANGED
@@ -19,10 +19,9 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency "bundler"
|
23
|
-
spec.add_development_dependency "
|
24
|
-
spec.add_development_dependency "
|
25
|
-
|
26
|
-
spec.
|
27
|
-
spec.add_dependency "more_core_extensions"
|
22
|
+
spec.add_development_dependency "bundler"
|
23
|
+
spec.add_development_dependency "manageiq-style"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
26
|
+
spec.add_development_dependency "simplecov", ">= 0.21.2"
|
28
27
|
end
|
data/renovate.json
ADDED
metadata
CHANGED
@@ -1,86 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: query_relation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Keenan Brock
|
8
8
|
- Jason Frey
|
9
|
-
autorequire:
|
10
9
|
bindir: exe
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: bundler
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
16
|
requirements:
|
18
|
-
- - "
|
17
|
+
- - ">="
|
19
18
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
19
|
+
version: '0'
|
21
20
|
type: :development
|
22
21
|
prerelease: false
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
24
23
|
requirements:
|
25
|
-
- - "
|
24
|
+
- - ">="
|
26
25
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
26
|
+
version: '0'
|
28
27
|
- !ruby/object:Gem::Dependency
|
29
|
-
name:
|
28
|
+
name: manageiq-style
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
31
30
|
requirements:
|
32
|
-
- - "
|
31
|
+
- - ">="
|
33
32
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
33
|
+
version: '0'
|
35
34
|
type: :development
|
36
35
|
prerelease: false
|
37
36
|
version_requirements: !ruby/object:Gem::Requirement
|
38
37
|
requirements:
|
39
|
-
- - "
|
38
|
+
- - ">="
|
40
39
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
40
|
+
version: '0'
|
42
41
|
- !ruby/object:Gem::Dependency
|
43
|
-
name:
|
42
|
+
name: rake
|
44
43
|
requirement: !ruby/object:Gem::Requirement
|
45
44
|
requirements:
|
46
|
-
- - "
|
45
|
+
- - ">="
|
47
46
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
47
|
+
version: '0'
|
49
48
|
type: :development
|
50
49
|
prerelease: false
|
51
50
|
version_requirements: !ruby/object:Gem::Requirement
|
52
51
|
requirements:
|
53
|
-
- - "
|
52
|
+
- - ">="
|
54
53
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
54
|
+
version: '0'
|
56
55
|
- !ruby/object:Gem::Dependency
|
57
|
-
name:
|
56
|
+
name: rspec
|
58
57
|
requirement: !ruby/object:Gem::Requirement
|
59
58
|
requirements:
|
60
|
-
- - "
|
59
|
+
- - "~>"
|
61
60
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0'
|
63
|
-
type: :
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
64
63
|
prerelease: false
|
65
64
|
version_requirements: !ruby/object:Gem::Requirement
|
66
65
|
requirements:
|
67
|
-
- - "
|
66
|
+
- - "~>"
|
68
67
|
- !ruby/object:Gem::Version
|
69
|
-
version: '0'
|
68
|
+
version: '3.0'
|
70
69
|
- !ruby/object:Gem::Dependency
|
71
|
-
name:
|
70
|
+
name: simplecov
|
72
71
|
requirement: !ruby/object:Gem::Requirement
|
73
72
|
requirements:
|
74
73
|
- - ">="
|
75
74
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
77
|
-
type: :
|
75
|
+
version: 0.21.2
|
76
|
+
type: :development
|
78
77
|
prerelease: false
|
79
78
|
version_requirements: !ruby/object:Gem::Requirement
|
80
79
|
requirements:
|
81
80
|
- - ">="
|
82
81
|
- !ruby/object:Gem::Version
|
83
|
-
version:
|
82
|
+
version: 0.21.2
|
84
83
|
description: Provides an ActiveRecord::Relation-like DSL to non-SQL backends
|
85
84
|
email:
|
86
85
|
- kbrock@redhat.com
|
@@ -89,9 +88,14 @@ executables: []
|
|
89
88
|
extensions: []
|
90
89
|
extra_rdoc_files: []
|
91
90
|
files:
|
91
|
+
- ".codeclimate.yml"
|
92
|
+
- ".github/workflows/ci.yaml"
|
92
93
|
- ".gitignore"
|
93
94
|
- ".rspec"
|
94
|
-
- ".
|
95
|
+
- ".rubocop.yml"
|
96
|
+
- ".rubocop_cc.yml"
|
97
|
+
- ".rubocop_local.yml"
|
98
|
+
- ".whitesource"
|
95
99
|
- CHANGELOG.md
|
96
100
|
- CODE_OF_CONDUCT.md
|
97
101
|
- Gemfile
|
@@ -104,11 +108,11 @@ files:
|
|
104
108
|
- lib/query_relation/queryable.rb
|
105
109
|
- lib/query_relation/version.rb
|
106
110
|
- query_relation.gemspec
|
111
|
+
- renovate.json
|
107
112
|
homepage: https://github.com/ManageIQ/query_relation
|
108
113
|
licenses:
|
109
114
|
- Apache-2.0
|
110
115
|
metadata: {}
|
111
|
-
post_install_message:
|
112
116
|
rdoc_options: []
|
113
117
|
require_paths:
|
114
118
|
- lib
|
@@ -123,9 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
127
|
- !ruby/object:Gem::Version
|
124
128
|
version: '0'
|
125
129
|
requirements: []
|
126
|
-
|
127
|
-
rubygems_version: 2.5.1
|
128
|
-
signing_key:
|
130
|
+
rubygems_version: 3.7.1
|
129
131
|
specification_version: 4
|
130
132
|
summary: Provides an ActiveRecord::Relation-like DSL to non-SQL backends
|
131
133
|
test_files: []
|