directiverecord 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CHANGELOG.rdoc +4 -0
- data/VERSION +1 -1
- data/lib/directive_record/query/sql.rb +13 -6
- data/lib/directive_record/version.rb +1 -1
- data/test/unit/query/test_mysql.rb +13 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
N2MxYzVmZWI5YjQxYWI0YjMwZTY2NDQzNWQwN2RiZTk4YzU4YjYxMQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OGNkNWI1NTdiMDg4MGNkZWU1MjBkNTAwMDg5Zjg1OGUzOGE4NzI4ZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmI5MGE4ZDBhNDNkZDYzMmU2ZTkzNmZmNTA1NDZlZjhmMDg2OGY4OGQ0ODk4
|
10
|
+
YTA1NGE1NGNkYjExYTM5OTkzNTA2NmU2ZTYyODVhMmQ3MjhkMGUxNDUzNTJj
|
11
|
+
ZjUxYWE0ZmEyMzA3MzZhYjgyZWM5NThkMmQwZjlkYjMzYmE0ZDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
Y2UwZGM3YTA2NDdmYTAzNTg5Yzk3Y2FmOTZiZTMzYzhlOTM0OTczZGM1ODg2
|
14
|
+
YTRiZThhODFiOTA4NDBmMWYyYzdhNDc2Mjg2NjRiODE3MDVmYmM1YjlkYzI3
|
15
|
+
NzQ2YmMyNDZmNDgzMjE5NGZjMjk4ZjJlN2U1NTFkYmRiZjYwYzI=
|
data/CHANGELOG.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.4
|
@@ -155,6 +155,11 @@ SQL
|
|
155
155
|
sql = sql.gsub(/ AS .*$/, "")
|
156
156
|
sql_alias = options[:aliases][prepend_base_alias(sql_alias || sql)] = "c#{array.size + 1}"
|
157
157
|
end
|
158
|
+
unless sql_alias
|
159
|
+
sql.match(/^(.*) AS (.*)$/)
|
160
|
+
sql = $1 if $1
|
161
|
+
sql_alias = $2
|
162
|
+
end
|
158
163
|
|
159
164
|
options[:aliases][sql] = sql_alias if sql_alias
|
160
165
|
|
@@ -168,14 +173,16 @@ SQL
|
|
168
173
|
end
|
169
174
|
|
170
175
|
def normalize_where!(options)
|
171
|
-
regexp = /^\S
|
176
|
+
regexp, aliases = /^\S+/, options[:aliases].invert
|
172
177
|
|
173
178
|
where, having = (options[:where] || []).partition do |statement|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
+
statement.gsub(/((?<![\\])['"])((?:.(?!(?<![\\])\1))*.?)\1/, " ")
|
180
|
+
.split(/\b(and|or)\b/i).reject{|sql| %w(and or).include? sql.downcase}
|
181
|
+
.collect{|sql| sql = sql.strip; (sql[0] == "(" && sql[-1] == ")" ? sql[1..-1] : sql)}
|
182
|
+
.all? do |sql|
|
183
|
+
sql.match /(.*)\s*(=|<=>|>=|>|<=|<|<>|!=|is|like|rlike|regexp|in|between|not|sounds|soundex)(\b|\s|$)/i
|
184
|
+
path = $1.strip rescue binding.pry
|
185
|
+
!(aliases[path] || path).match(/\b(count|sum|min|max|avg)\(/i)
|
179
186
|
end
|
180
187
|
end
|
181
188
|
|
@@ -55,7 +55,7 @@ module Unit
|
|
55
55
|
LIMIT 5
|
56
56
|
}
|
57
57
|
),
|
58
|
-
Customer.to_qry("id, name, COUNT(orders.id) AS order_count, GROUP_CONCAT(DISTINCT tags.name) AS tags", :group_by => "id", :order_by => "COUNT(DISTINCT tags.id) DESC", :limit => 5)
|
58
|
+
Customer.to_qry("id", "name", "COUNT(orders.id) AS order_count", "GROUP_CONCAT(DISTINCT tags.name) AS tags", :group_by => "id", :order_by => "COUNT(DISTINCT tags.id) DESC", :limit => 5)
|
59
59
|
)
|
60
60
|
|
61
61
|
assert_equal(
|
@@ -97,7 +97,7 @@ module Unit
|
|
97
97
|
ORDER BY `c`.id
|
98
98
|
}
|
99
99
|
),
|
100
|
-
Customer.to_qry("id, name, COUNT(orders.id) AS order_count", :where => "order_count > 3", :group_by => "id")
|
100
|
+
Customer.to_qry("id", "name", "COUNT(orders.id) AS order_count", :where => "order_count > 3", :group_by => "id")
|
101
101
|
)
|
102
102
|
|
103
103
|
$default_office_scope = {:id => [1, 3, 6]}
|
@@ -195,6 +195,17 @@ module Unit
|
|
195
195
|
Employee.where(["first_name LIKE ?", "%y"]).to_qry
|
196
196
|
)
|
197
197
|
|
198
|
+
assert_equal(
|
199
|
+
strip(
|
200
|
+
%Q{
|
201
|
+
SELECT `e`.*
|
202
|
+
FROM employees `e`
|
203
|
+
WHERE (LOWER(`e`.first_name) LIKE '%y')
|
204
|
+
}
|
205
|
+
),
|
206
|
+
Employee.where(["LOWER(first_name) LIKE ?", "%y"]).to_qry
|
207
|
+
)
|
208
|
+
|
198
209
|
assert_equal(
|
199
210
|
strip(
|
200
211
|
%Q{
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.4
|
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-01-
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|