quo 0.5.1 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/README.md +33 -0
- data/lib/quo/merged_query.rb +2 -2
- data/lib/quo/results.rb +0 -3
- data/lib/quo/version.rb +1 -1
- data/sig/quo/merged_query.rbs +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d20b292ae3178fa1ce96705049b215f37d4966a44ee9d05b4fafda3a664a9f5
|
4
|
+
data.tar.gz: a151bfb1c35dcfea765d3aac5b1bf501c842288e99529523dadf410c0243fe04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd0e575917052a3171dd45eada04a0ad0e0c670154294507a76808e5bc508d21d8aa53bdad3deebdea11f57a91193c1ae4132589dc330a273b3dda588f635d2f
|
7
|
+
data.tar.gz: 3faaa3f25cb76d44b70c28425f42f582ed58a7b83c573d976019caef302e4bceeedb8f93912250de7e80b3a906042820eb9884049891c75f5971e3a143361006
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -130,6 +130,38 @@ composed = query1 + query2 # or Quo::Query.compose(query1, query2) or query1.com
|
|
130
130
|
composed.first
|
131
131
|
```
|
132
132
|
|
133
|
+
```ruby
|
134
|
+
class CompanyToBeApproved < Quo::TypedQuery
|
135
|
+
def query
|
136
|
+
Registration
|
137
|
+
.left_joins(:approval)
|
138
|
+
.where(approvals: {completed_at: nil})
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
class CompanyInUsCityAndState < Quo::TypedQuery
|
143
|
+
param :state, Literal::Union[String, Array[String]]
|
144
|
+
param :city, optional(Literal::Union[String, Array[String]])
|
145
|
+
|
146
|
+
def query
|
147
|
+
q = Registration
|
148
|
+
.joins(company: :address)
|
149
|
+
.where(addresses: {state: state})
|
150
|
+
q = q.where(addresses: {city: city}) if city
|
151
|
+
q
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
query1 = CompanyToBeApproved.new
|
157
|
+
query_partialy_applied = CompanyInUsState.with(state: "California")
|
158
|
+
query2 = query_partialy_applied.with(city: ["San Francisco", "Los Angeles"]).operation
|
159
|
+
|
160
|
+
composed = query1 + query2
|
161
|
+
# '+' composes the queries and returns a new prepared query
|
162
|
+
composed.first
|
163
|
+
```
|
164
|
+
|
133
165
|
This effectively executes:
|
134
166
|
|
135
167
|
```ruby
|
@@ -138,6 +170,7 @@ Registration
|
|
138
170
|
.joins(company: :address)
|
139
171
|
.where(approvals: {completed_at: nil})
|
140
172
|
.where(addresses: {state: options[:state]})
|
173
|
+
.limit(1)
|
141
174
|
```
|
142
175
|
|
143
176
|
It is also possible to compose with an `ActiveRecord::Relation`. This can be useful in a Query object itself to help
|
data/lib/quo/merged_query.rb
CHANGED
@@ -17,7 +17,7 @@ module Quo
|
|
17
17
|
self.class.new(query, left, right, **@options.merge(options))
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def inspect
|
21
21
|
"Quo::MergedQuery[#{operand_desc(left)}, #{operand_desc(right)}]"
|
22
22
|
end
|
23
23
|
|
@@ -27,7 +27,7 @@ module Quo
|
|
27
27
|
|
28
28
|
def operand_desc(operand)
|
29
29
|
if operand.is_a? Quo::MergedQuery
|
30
|
-
operand.
|
30
|
+
operand.inspect
|
31
31
|
else
|
32
32
|
operand.class.name || "(anonymous)"
|
33
33
|
end
|
data/lib/quo/results.rb
CHANGED
@@ -3,9 +3,6 @@
|
|
3
3
|
require "forwardable"
|
4
4
|
require_relative "./utilities/callstack"
|
5
5
|
|
6
|
-
# TODO: can the results be more like a monad, so we can provide success vs failure ... or
|
7
|
-
# maybe it is a enumerable-like but it can also be pattern matched?
|
8
|
-
|
9
6
|
module Quo
|
10
7
|
class Results
|
11
8
|
extend Forwardable
|
data/lib/quo/version.rb
CHANGED
data/sig/quo/merged_query.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: quo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -114,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
114
|
- !ruby/object:Gem::Version
|
115
115
|
version: '0'
|
116
116
|
requirements: []
|
117
|
-
rubygems_version: 3.4.
|
117
|
+
rubygems_version: 3.4.19
|
118
118
|
signing_key:
|
119
119
|
specification_version: 4
|
120
120
|
summary: Quo is a query object gem for Rails
|