sqlstmt 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sqlstmt/sqlstmt.rb +9 -0
- data/test/select_test.rb +7 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e5442989dabb7b5853e3a3a2da09e295f07e9eb1
|
4
|
+
data.tar.gz: c04ff3e2ed10a3ba5a1fd5c259a0ec4313fcb988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a6fd7b98ad716bbfb7bec82e623776fed16c1cfc34789356e886c10d381ed4325dd149f3705ab5934d8e3dcfb3b4cbff30c5af683a5f64ab6e8268ebba5286b
|
7
|
+
data.tar.gz: c74f8c9bf16840f8b8e91356a3072072dfce72485c14cb8e94f4a56a88defebd80c440da0056be2963ffc8729e9ff2d89e8f8ee99c4ac9a2344fdb0cb9f75dd0
|
data/lib/sqlstmt/sqlstmt.rb
CHANGED
@@ -25,6 +25,7 @@ class SqlStmt
|
|
25
25
|
@replace = nil
|
26
26
|
@ignore = ''
|
27
27
|
@outfile = ''
|
28
|
+
@with_rollup = nil
|
28
29
|
# track this explicitly to guarantee get is not used with non-select statements
|
29
30
|
@called_get = false
|
30
31
|
end
|
@@ -141,6 +142,11 @@ class SqlStmt
|
|
141
142
|
return self
|
142
143
|
end
|
143
144
|
|
145
|
+
def with_rollup
|
146
|
+
@with_rollup = true
|
147
|
+
return self
|
148
|
+
end
|
149
|
+
|
144
150
|
# used with INSERT statements only
|
145
151
|
def into(into_table)
|
146
152
|
@into_table = into_table
|
@@ -303,6 +309,9 @@ private
|
|
303
309
|
def build_from_clause
|
304
310
|
join_clause = build_join_clause
|
305
311
|
group_clause = simple_clause('GROUP BY', @group_by)
|
312
|
+
if @with_rollup
|
313
|
+
group_clause += ' WITH ROLLUP'
|
314
|
+
end
|
306
315
|
order_clause = simple_clause('ORDER BY', @order_by)
|
307
316
|
limit_clause = simple_clause('LIMIT', @limit)
|
308
317
|
having_clause = @having.empty? ? '' : " HAVING #{@having.join(' AND ')}"
|
data/test/select_test.rb
CHANGED
@@ -32,6 +32,13 @@ class TestSelect < Minitest::Test
|
|
32
32
|
assert_equal('SELECT blah FROM source HAVING blee > 0', SqlStmt.new.select.table('source').get('blah').no_where.having('blee > 0').to_s)
|
33
33
|
end
|
34
34
|
|
35
|
+
def test_group_by
|
36
|
+
sqlb = SqlStmt.new.select.table('source').get('blah').no_where.group_by('blah')
|
37
|
+
assert_equal('SELECT blah FROM source GROUP BY blah', sqlb.to_s)
|
38
|
+
sqlb.with_rollup
|
39
|
+
assert_equal('SELECT blah FROM source GROUP BY blah WITH ROLLUP', sqlb.to_s)
|
40
|
+
end
|
41
|
+
|
35
42
|
def test_duplicate_joins
|
36
43
|
sqlb = SqlStmt.new.select.table('source s').get('frog').no_where
|
37
44
|
4.times { sqlb.join('other o', 's.blah_id = o.blah_id') }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sqlstmt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Makani Mason
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-06 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: build SQL statements in a modular fashion, one piece at a time; only
|
15
15
|
used/tested with MySQL so far
|
@@ -51,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
51
|
version: '0'
|
52
52
|
requirements: []
|
53
53
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.
|
54
|
+
rubygems_version: 2.6.8
|
55
55
|
signing_key:
|
56
56
|
specification_version: 4
|
57
57
|
summary: build SQL statements in a modular fashion, one piece at a time
|