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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YjcwZWZhNjNhZThlMWQyOWU4NGIyNzE1YTRiNjQ5N2UzYWE2OGUzYQ==
4
+ N2MxYzVmZWI5YjQxYWI0YjMwZTY2NDQzNWQwN2RiZTk4YzU4YjYxMQ==
5
5
  data.tar.gz: !binary |-
6
- NjcxNWM5NTc2NzEzZTNiNTUwNjczMTA4MjAzMzUwMGViMTYzMjRlNA==
6
+ OGNkNWI1NTdiMDg4MGNkZWU1MjBkNTAwMDg5Zjg1OGUzOGE4NzI4ZQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NGFkZTNiN2EyN2NhZTc4YjE0ZjY2MjE0M2EwMGZiYjc2OGZjODk4OTE5MjZm
10
- ZTIzZWQ3ZTRjODU3YWYxMDhmOTJiNTgwMWM1ODZmZWM3OTc1YzQ4YTczZjVi
11
- Y2M3YWRiYjYxZTllNzIxMzU4MzFlMzQ3MDBiMTllNzMwYjdiNjY=
9
+ NmI5MGE4ZDBhNDNkZDYzMmU2ZTkzNmZmNTA1NDZlZjhmMDg2OGY4OGQ0ODk4
10
+ YTA1NGE1NGNkYjExYTM5OTkzNTA2NmU2ZTYyODVhMmQ3MjhkMGUxNDUzNTJj
11
+ ZjUxYWE0ZmEyMzA3MzZhYjgyZWM5NThkMmQwZjlkYjMzYmE0ZDM=
12
12
  data.tar.gz: !binary |-
13
- MDhmZWNlZDY2Njc1OWM4ZjM4NzkxMWI3ODhmMTJjZDU5NmM2MDU5M2YxNWJj
14
- Y2Y5YWI4MGJhNTRmOTI1MWU5ZTc0M2Y3Y2VjMzUyNjBjOTk4Y2FjMjA2MTUz
15
- OTU4NzE2M2E2YmM3YTA4OTZlOGIwMDBlYzdiMGM2MGYyMDk1MWQ=
13
+ Y2UwZGM3YTA2NDdmYTAzNTg5Yzk3Y2FmOTZiZTMzYzhlOTM0OTczZGM1ODg2
14
+ YTRiZThhODFiOTA4NDBmMWYyYzdhNDc2Mjg2NjRiODE3MDVmYmM1YjlkYzI3
15
+ NzQ2YmMyNDZmNDgzMjE5NGZjMjk4ZjJlN2U1NTFkYmRiZjYwYzI=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,9 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.4 (January 22, 2015)
4
+
5
+ * Improved partitioning conditions to WHERE or HAVING which fixes conditions with non-aggregate functions (e.g. LOWER)
6
+
3
7
  == Version 0.1.3 (January 21, 2015)
4
8
 
5
9
  * Added trend query support
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
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
- !options[:aggregated].keys.include?(statement.strip.match(regexp).to_s) &&
175
- statement.downcase.gsub(/((?<![\\])['"])((?:.(?!(?<![\\])\1))*.?)\1/, " ")
176
- .scan(/([a-zA-Z_\.]+)?\s*(=|<=>|>=|>|<=|<|<>|!=|is|like|rlike|regexp|in|between|not|sounds|soundex)(\b|\s)/)
177
- .all? do |(path, operator)|
178
- path && column_for(path)
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
 
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 3
4
+ TINY = 4
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -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.3
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-21 00:00:00.000000000 Z
11
+ date: 2015-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord