rusql 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/rusql/query.rb +13 -1
- data/lib/rusql/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ca832a09fdf83cd1c64656927c8c556aa434b95
|
4
|
+
data.tar.gz: d87e61a4e1dd20c0cc6e945ca72ea1de0d1c1088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7b9101f8172c1283da78d13c712e9fdc2663f836af9841a66789e1e8e443a398f71b7c639a551aea118735bb1d76341668ac9c8f5fe77ab03ba6e3f0719f0cd0
|
7
|
+
data.tar.gz: 60a2f17ea4aabdb96d789d32e7fb7c2209061098a2f76c5c7c9ef2246bcb1c6e0b179708dc769da3d3501607bd5f70c91f7879a5b29ade2e175aba8a253bd9fd
|
data/README.md
CHANGED
@@ -49,7 +49,7 @@ end
|
|
49
49
|
|
50
50
|
## Contributing
|
51
51
|
|
52
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
52
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sparkymat/rusql. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
53
53
|
|
54
54
|
|
55
55
|
## License
|
data/lib/rusql/query.rb
CHANGED
@@ -8,12 +8,14 @@ module Rusql
|
|
8
8
|
@selectors = selectors
|
9
9
|
@joins = []
|
10
10
|
@orders = []
|
11
|
+
@group_by = nil
|
11
12
|
end
|
12
13
|
|
13
14
|
def duplicate
|
14
15
|
new_one = Query.new(self.instance_variable_get(:@selectors))
|
15
16
|
new_one.instance_variable_set( :@condition, self.instance_variable_get(:@condition) )
|
16
17
|
new_one.instance_variable_set( :@from_table, self.instance_variable_get(:@from_table) )
|
18
|
+
new_one.instance_variable_set( :@group_by, self.instance_variable_get(:@group_by) )
|
17
19
|
new_one.instance_variable_set( :@joins, self.instance_variable_get(:@joins) )
|
18
20
|
new_one.instance_variable_set( :@limit, self.instance_variable_get(:@limit) )
|
19
21
|
new_one.instance_variable_set( :@orders, self.instance_variable_get(:@orders) )
|
@@ -50,6 +52,15 @@ module Rusql
|
|
50
52
|
new_one
|
51
53
|
end
|
52
54
|
|
55
|
+
def group_by(c)
|
56
|
+
raise TypeException.new(Column, c.class) unless c.is_a?(Column)
|
57
|
+
|
58
|
+
new_one = self.duplicate
|
59
|
+
new_one.instance_variable_set(:@group_by, c)
|
60
|
+
|
61
|
+
new_one
|
62
|
+
end
|
63
|
+
|
53
64
|
def join(join)
|
54
65
|
raise TypeException.new(Join, join.class) unless join.is_a?(Join)
|
55
66
|
|
@@ -96,6 +107,7 @@ module Rusql
|
|
96
107
|
join_part = @joins.map{ |j| "\n#{j.to_s}" }.join
|
97
108
|
where_part = "\nWHERE"
|
98
109
|
order_part = "\nORDER BY #{ @orders.map(&:to_s).join(", ") }"
|
110
|
+
group_by_part = "\nGROUP BY #{ @group_by&.to_s }"
|
99
111
|
|
100
112
|
if @condition.is_a?(BasicCondition)
|
101
113
|
where_part += " "
|
@@ -108,7 +120,7 @@ module Rusql
|
|
108
120
|
<<-EOS
|
109
121
|
SELECT
|
110
122
|
#{ @selectors.map{ |s| " #{s.to_s}" }.join(",\n") }
|
111
|
-
FROM #{ @from_table.to_s_for_aliasing }#{ (@joins.length > 0) ? join_part : "" }#{ @condition.nil? ? "" : where_part }#{ @orders.length > 0 ? order_part : "" }
|
123
|
+
FROM #{ @from_table.to_s_for_aliasing }#{ (@joins.length > 0) ? join_part : "" }#{ @condition.nil? ? "" : where_part }#{ @orders.length > 0 ? order_part : "" }#{ @group_by.nil? ? "" : group_by_part }
|
112
124
|
EOS
|
113
125
|
end
|
114
126
|
end
|
data/lib/rusql/version.rb
CHANGED