rusql 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3adb1f9c5efd4c5bcd9b68068b29cd72feb2ab20
4
- data.tar.gz: 9bffc7fe874eeaeae32f01a64d626d1ff112268c
3
+ metadata.gz: 6ca832a09fdf83cd1c64656927c8c556aa434b95
4
+ data.tar.gz: d87e61a4e1dd20c0cc6e945ca72ea1de0d1c1088
5
5
  SHA512:
6
- metadata.gz: 41d27ede4646bb3635e26a27d41de33a70170477325eea98094ed222de8b9ef176de857514c73276e00bcb32d56f699259641b084a6da7c23ad980e58a935d67
7
- data.tar.gz: e7f6cf7008ad2a8aaf4c3226ef4dcdca1b9a8abf9403633a2a478a4ce4d2458bc17b16b80b1746a67e1a1d7dc4fcde6bc86af3e805f1780871ea056d53ca5505
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/[USERNAME]/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.
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
@@ -1,3 +1,3 @@
1
1
  module Rusql
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rusql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ajith Hussain