directiverecord 0.1.11 → 0.1.12
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/CHANGELOG.rdoc +5 -0
- data/VERSION +1 -1
- data/lib/directive_record/query/sql.rb +12 -5
- data/lib/directive_record/version.rb +1 -1
- data/test/unit/query/test_big_query.rb +16 -0
- data/test/unit/query/test_mysql.rb +12 -4
- metadata +24 -24
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YTdmNzI2MjM4ZTI4NzA3NDBmZGI2NTAwMGI1OGZhNDAwNDJjNzBiNA==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df721b5ec99c98a868667e250aea31187c079bea
|
4
|
+
data.tar.gz: f7ef75ed7fb5f252622ad38f7def0e17a44aba60
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
OGM5NzcwYWM1NjE5ZTBiMzcxZDQxYzA3NGZlZWYxZDA4M2RmYjU1OWI0ZTE5
|
11
|
-
YzEzMDQyYTEwMjkwNGFiYzg0MjBkYTQyNjU2ZmM2NGM4ZmE0YWY=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YmM4OTgxZDc3NzJjZTY0ZjhiNjQwYjhiNDZhYTc4OWU5ZDgyNzY5ZmI0MGY5
|
14
|
-
MTBjZDg2NTYxOWYyZTk3MzM5NDUxYjQyMjRmZTQxMDFmZDg4NGM1OTk0MzIy
|
15
|
-
NmExMTA4MmZlN2EzMGQwYjllZGFiYzc0M2JlYzI1OWMzMDJjNzc=
|
6
|
+
metadata.gz: 732c2dfe564ef73a4ede1fc6a5d710570a232eae2815fdc125fae9bd65310f8a75f7453279a00139367e54f29ef809acd029971fa2d31a8ae219d22ec476aa61
|
7
|
+
data.tar.gz: b7a5ec354819ec0c0cf68e5591c621e5f2457356858d63702fc68ed723ff77a08be74e3d993ee4b66a647986edd91ce9842042583ef4de3351b0a2f9dc49d68c
|
data/CHANGELOG.rdoc
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
= DirectiveRecord CHANGELOG
|
2
2
|
|
3
|
+
== Version 0.1.12 (March 8, 2015)
|
4
|
+
|
5
|
+
* Being able to specify calculated :group_by option
|
6
|
+
* Not adding ORDER BY statement automatically
|
7
|
+
|
3
8
|
== Version 0.1.11 (March 6, 2015)
|
4
9
|
|
5
10
|
* Counting ‘DISTINCT id’ instead of ‘*’ in ActiveRecord::Relation#count(:all) override
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.12
|
@@ -117,6 +117,7 @@ SQL
|
|
117
117
|
normalize_select!(options)
|
118
118
|
normalize_from!(options)
|
119
119
|
normalize_where!(options)
|
120
|
+
normalize_group_by!(options)
|
120
121
|
normalize_order_by!(options)
|
121
122
|
options.reject!{|k, v| v.blank?}
|
122
123
|
end
|
@@ -196,12 +197,18 @@ SQL
|
|
196
197
|
end
|
197
198
|
end
|
198
199
|
|
199
|
-
def
|
200
|
-
options[:
|
201
|
-
|
202
|
-
|
203
|
-
|
200
|
+
def normalize_group_by!(options)
|
201
|
+
options[:group_by].collect! do |x|
|
202
|
+
if x.match(/ AS (\w+)$/)
|
203
|
+
options[:select] << x unless options[:select].include?(x)
|
204
|
+
$1
|
205
|
+
else
|
206
|
+
x
|
207
|
+
end
|
208
|
+
end if options[:group_by]
|
209
|
+
end
|
204
210
|
|
211
|
+
def normalize_order_by!(options)
|
205
212
|
return unless options[:order_by]
|
206
213
|
|
207
214
|
options[:order_by].collect! do |x|
|
@@ -76,6 +76,22 @@ module Unit
|
|
76
76
|
:period => "order_date"
|
77
77
|
).strip.gsub(/\s+/, " ")
|
78
78
|
)
|
79
|
+
|
80
|
+
assert_equal(
|
81
|
+
%Q{
|
82
|
+
SELECT COUNT(id), YEAR(order_date) AS year
|
83
|
+
FROM
|
84
|
+
TABLE_DATE_RANGE(my_stats.orders_, TIMESTAMP('2015-01-15'), TIMESTAMP('2015-01-21'))
|
85
|
+
GROUP BY year
|
86
|
+
}.strip.gsub(/\s+/, " "),
|
87
|
+
Order.to_qry(
|
88
|
+
"COUNT(id)",
|
89
|
+
:connection => BigQuery.connection,
|
90
|
+
:where => "order_date >= '2015-01-15' AND order_date <= '2015-01-21'",
|
91
|
+
:group_by => "YEAR(order_date) AS year",
|
92
|
+
:period => "order_date"
|
93
|
+
).strip.gsub(/\s+/, " ")
|
94
|
+
)
|
79
95
|
end
|
80
96
|
end
|
81
97
|
|
@@ -90,7 +90,6 @@ module Unit
|
|
90
90
|
LEFT JOIN tags `tags` ON `tags`.id = `tags_bridge_table`.tag_id
|
91
91
|
WHERE (`tags`.name LIKE '%gifts%')
|
92
92
|
GROUP BY `tags`.id
|
93
|
-
ORDER BY `tags`.id
|
94
93
|
}
|
95
94
|
),
|
96
95
|
Customer.where("tags.name LIKE ?", "%gifts%").group("tags.id").to_qry("tags.*")
|
@@ -104,7 +103,6 @@ module Unit
|
|
104
103
|
LEFT JOIN orders `orders` ON `orders`.customer_id = `c`.id
|
105
104
|
GROUP BY `c`.id
|
106
105
|
HAVING (order_count > 3)
|
107
|
-
ORDER BY `c`.id
|
108
106
|
}
|
109
107
|
),
|
110
108
|
Customer.to_qry("id", "name", "COUNT(orders.id) AS order_count", :where => "order_count > 3", :group_by => "id")
|
@@ -174,7 +172,6 @@ module Unit
|
|
174
172
|
SELECT ROUND(SUM(`od`.price_each), 2) AS `sum:price_each`
|
175
173
|
FROM order_details `od`
|
176
174
|
GROUP BY `od`.order_id
|
177
|
-
ORDER BY `od`.order_id
|
178
175
|
}
|
179
176
|
),
|
180
177
|
OrderDetail.to_qry("price_each", :aggregates => {"price_each" => :sum}, :group_by => "order_id")
|
@@ -187,7 +184,6 @@ module Unit
|
|
187
184
|
FROM order_details `od`
|
188
185
|
LEFT JOIN orders `order` ON `order`.id = `od`.order_id
|
189
186
|
GROUP BY c1
|
190
|
-
ORDER BY c1
|
191
187
|
}
|
192
188
|
),
|
193
189
|
OrderDetail.to_qry("order.id", "price_each", :aggregates => {"price_each" => :sum}, :group_by => "order.id", :numerize_aliases => true)
|
@@ -250,6 +246,18 @@ module Unit
|
|
250
246
|
),
|
251
247
|
Office.usa.to_qry
|
252
248
|
)
|
249
|
+
|
250
|
+
assert_equal(
|
251
|
+
strip(
|
252
|
+
%Q{
|
253
|
+
SELECT `o`.*, YEAR(created_at) AS year
|
254
|
+
FROM offices `o`
|
255
|
+
WHERE (`o`.country = 'USA')
|
256
|
+
GROUP BY year
|
257
|
+
}
|
258
|
+
),
|
259
|
+
Office.usa.to_qry(:group_by => "YEAR(created_at) AS year")
|
260
|
+
)
|
253
261
|
end
|
254
262
|
end
|
255
263
|
|
metadata
CHANGED
@@ -1,139 +1,139 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: directiverecord
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Engel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 3.2.13
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.2.13
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: arel
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - <
|
31
|
+
- - "<"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 6.0.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - <
|
38
|
+
- - "<"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 6.0.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: yard
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: pry
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: mysql2
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: simplecov
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: minitest
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
|
-
- -
|
115
|
+
- - ">="
|
116
116
|
- !ruby/object:Gem::Version
|
117
117
|
version: '0'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
|
-
- -
|
122
|
+
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: mocha
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
|
-
- -
|
129
|
+
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
type: :development
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
|
-
- -
|
136
|
+
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
description: A layer on top of ActiveRecord for using paths within queries without
|
@@ -143,7 +143,7 @@ executables: []
|
|
143
143
|
extensions: []
|
144
144
|
extra_rdoc_files: []
|
145
145
|
files:
|
146
|
-
- .gitignore
|
146
|
+
- ".gitignore"
|
147
147
|
- CHANGELOG.rdoc
|
148
148
|
- Gemfile
|
149
149
|
- MIT-LICENSE
|
@@ -195,17 +195,17 @@ require_paths:
|
|
195
195
|
- lib
|
196
196
|
required_ruby_version: !ruby/object:Gem::Requirement
|
197
197
|
requirements:
|
198
|
-
- -
|
198
|
+
- - ">="
|
199
199
|
- !ruby/object:Gem::Version
|
200
200
|
version: '0'
|
201
201
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
202
202
|
requirements:
|
203
|
-
- -
|
203
|
+
- - ">="
|
204
204
|
- !ruby/object:Gem::Version
|
205
205
|
version: '0'
|
206
206
|
requirements: []
|
207
207
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.
|
208
|
+
rubygems_version: 2.2.2
|
209
209
|
signing_key:
|
210
210
|
specification_version: 4
|
211
211
|
summary: A layer on top of ActiveRecord for using paths within queries without thinking
|