directiverecord 0.1.0 → 0.1.1

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
- YjYwOWJkMDk4YmUyZWZkMjcwMThiZDk4NzQ1ZTUzMzJiM2YwYzg1NQ==
4
+ OTI2YTQyODBjY2FmMmJmYjgyNzZiNDVmOGRjMDA3MjBmNTA1MGQ0ZA==
5
5
  data.tar.gz: !binary |-
6
- YjA3MDE0YmRjYjA4NTc3NjMyYmZkOGEzMTc4NGUzMjk2NGMwYzgwOQ==
6
+ YzQ5ODk1MzAxMWYxM2Q1ZDBmNTE4MjkwYTAyMTEyOTM1MjA4OGNlYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmUxZGI1YmYxNWIzMjMyOGM5MWY2NmFmYWMxZGRlOTEyZjFmYjI3ZWE1Mjdk
10
- M2MwNGIxYzIzMmYwZWU5ZTNiMGJjZmQ5MmRhNjNjNjAyNzdiNmVmZjk2NjYy
11
- NmU4YTc1ODg4OWFkMmRkZmVhMzQ3MjAxMTc1ZmFiNjZmNTI4YzA=
9
+ ZTEyNjY3NDVkMmQ1YzUzMTg2ZjU3MjdhZDdlYmY1YTk1NjUzMGU3ODdiODE1
10
+ YzdkMzUwYTU1ZDA1NmFmNDE0N2IxMDdlM2NmMTc0ZTZmODg2NTcyMDBlNTE2
11
+ ZjA2YTNiMTQ0MGU4N2E1MmE1MzkyOGJjMmY3YjU0YjU1NzI5NmE=
12
12
  data.tar.gz: !binary |-
13
- YzdiM2Q0ZDI2ODFmMGJiNWNiY2M3MWU1ODQzMjUwMWViZDMxNWU2NzRkYmEy
14
- MTBhZTMyN2YyMTVhZWZjOTU4NGYxMjBiYmRjZDg1YTExYTYyNDRkNTVhNTRh
15
- YjJjZDhjNDFmZDAyMjgxOWZmYzdjY2Y1NDMyN2RhZDQ4NTA4MjM=
13
+ YmFmZWQ5Y2E3NDI4MjUzNzQ1ZTJkYzAwMjE1YmFhMmQ1ODM2ZmUyYzAzZTcw
14
+ ZTk0YmRlMzNlMThkZWFjOWEzMDcxZmI3YTU3ODFhYTRhMTlmYzRlOTNjM2Rl
15
+ ZDA4MmQ1ODc1YmUzMDMxODMxMmMzZjkzMDI0MmZhYzI0OGI0NWI=
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,10 @@
1
1
  = DirectiveRecord CHANGELOG
2
2
 
3
+ == Version 0.1.1 (January 19, 2015)
4
+
5
+ * Optimizing query when passing :optimize => true and having paths within the select statement
6
+ * Dropped MonetDB support
7
+
3
8
  == Version 0.1.0 (December 1, 2014)
4
9
 
5
10
  * Initial release
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
@@ -1,6 +1,5 @@
1
1
  require "directive_record/query/sql"
2
2
  require "directive_record/query/mysql"
3
- require "directive_record/query/monetdb"
4
3
 
5
4
  module DirectiveRecord
6
5
  module Query
@@ -14,10 +13,8 @@ module DirectiveRecord
14
13
  def self.class_for(connection_class)
15
14
  if connection_class.include?("mysql")
16
15
  MySQL
17
- elsif connection_class.include?("monetdb")
18
- MonetDB
19
16
  else
20
- raise NotImplementedError
17
+ raise NotImplementedError, "Connection type not supported"
21
18
  end
22
19
  end
23
20
 
@@ -64,12 +64,12 @@ module DirectiveRecord
64
64
  end
65
65
 
66
66
  def validate_options!(options)
67
- options.assert_valid_keys :select, :where, :group_by, :order_by, :limit, :offset, :aggregates, :numerize_aliases
67
+ options.assert_valid_keys :select, :where, :group_by, :order_by, :limit, :offset, :aggregates, :numerize_aliases, :optimize
68
68
  end
69
69
 
70
70
  def optimize_query!(options)
71
71
  select = [options[:select]].flatten
72
- if options[:where] && (select != %w(id)) && select.any?{|x| x.match(/^\w+(\.\w+)+$/)}
72
+ if options[:optimize] && (select != %w(id)) && select.any?{|x| x.match(/^\w+(\.\w+)+$/)}
73
73
  ids = base.connection.select_values(to_sql(options.merge(:select => "id"))).uniq + [0]
74
74
  options[:where] = ["id IN (#{ids.join(", ")})"]
75
75
  options.delete :limit
@@ -1,7 +1,7 @@
1
1
  module DirectiveRecord
2
2
  MAJOR = 0
3
3
  MINOR = 1
4
- TINY = 0
4
+ TINY = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, TINY].join(".")
7
7
  end
@@ -217,7 +217,7 @@ module Unit
217
217
  ORDER BY `office`.city, `e`.last_name, `e`.first_name
218
218
  }
219
219
  ),
220
- Employee.to_qry("id", "office.city", :where => "office_id = 1", :order_by => "office.city, last_name, first_name")
220
+ Employee.to_qry("id", "office.city", :where => "office_id = 1", :order_by => "office.city, last_name, first_name", :optimize => true)
221
221
  )
222
222
 
223
223
  assert_equal(
@@ -20,12 +20,6 @@ module Unit
20
20
  end
21
21
  end
22
22
 
23
- describe "when MonetDB" do
24
- it "returns the DirectiveRecord::Query::MonetDB class" do
25
- assert_equal DirectiveRecord::Query::MonetDB, DirectiveRecord::Query.send(:class_for, "monetdb::connection")
26
- end
27
- end
28
-
29
23
  describe "when else" do
30
24
  it "raises a NotImplementedError" do
31
25
  assert_raises NotImplementedError do
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.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Engel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-01 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -143,7 +143,6 @@ files:
143
143
  - lib/directive_record/gem_ext/active_record/base.rb
144
144
  - lib/directive_record/gem_ext/active_record/relation.rb
145
145
  - lib/directive_record/query.rb
146
- - lib/directive_record/query/monetdb.rb
147
146
  - lib/directive_record/query/mysql.rb
148
147
  - lib/directive_record/query/sql.rb
149
148
  - lib/directive_record/relation.rb
@@ -165,7 +164,6 @@ files:
165
164
  - test/test_helper/coverage.rb
166
165
  - test/unit/gem_ext/active_record/test_base.rb
167
166
  - test/unit/gem_ext/active_record/test_relation.rb
168
- - test/unit/query/test_monetdb.rb
169
167
  - test/unit/query/test_mysql.rb
170
168
  - test/unit/query/test_sql.rb
171
169
  - test/unit/test_directive_record.rb
@@ -212,7 +210,6 @@ test_files:
212
210
  - test/test_helper/coverage.rb
213
211
  - test/unit/gem_ext/active_record/test_base.rb
214
212
  - test/unit/gem_ext/active_record/test_relation.rb
215
- - test/unit/query/test_monetdb.rb
216
213
  - test/unit/query/test_mysql.rb
217
214
  - test/unit/query/test_sql.rb
218
215
  - test/unit/test_directive_record.rb
@@ -1,54 +0,0 @@
1
- module DirectiveRecord
2
- module Query
3
- class MonetDB < SQL
4
-
5
- private
6
-
7
- def path_delimiter
8
- "__"
9
- end
10
-
11
- def aggregate_delimiter
12
- "__"
13
- end
14
-
15
- def group_by_all_sql
16
- "all_rows"
17
- end
18
-
19
- def prepare_options!(options)
20
- normalize_group_by! options
21
- [:select, :where, :having, :group_by, :order_by].each do |key|
22
- if options[key]
23
- base.reflections.keys.each do |association|
24
- options[key] = [options[key]].flatten.collect{|x| x.gsub(/^#{association}\.([a-z_\.]+)/) { "#{association}_#{$1.gsub(".", "_")}" }}
25
- end
26
- end
27
- end
28
- end
29
-
30
- def finalize_options!(options)
31
- if options[:having]
32
- if options[:numerize_aliases]
33
- map = Hash[options[:select].scan(/,?\s?(.*?) AS ([^,]+)/).collect(&:reverse)]
34
- options[:aliases].each{|pattern, replacement| options[:having].gsub! pattern, map[replacement]}
35
- else
36
- (options[:aggregates] || {}).each do |path, aggregate|
37
- options[:having].gsub! /\b#{aggregate}__#{path}\b/, "#{aggregate.to_s.upcase}(#{path})"
38
- end
39
- end
40
- end
41
-
42
- options[:select] = options[:select].split(", ").collect do |string|
43
- expression, query_alias = string.match(/^(.*) AS (.*)$/).try(:captures)
44
- if query_alias
45
- options[:group_by].to_s.include?(expression) || !expression.match(/^\w+(\.\w+)*$/) ? string : "MAX(#{expression}) AS #{query_alias}"
46
- else
47
- string.match(/^\w+(\.\w+)*$/) ? "MAX(#{string})" : string
48
- end
49
- end.join(", ") if options[:group_by]
50
- end
51
-
52
- end
53
- end
54
- end
@@ -1,27 +0,0 @@
1
- require_relative "../../test_helper"
2
-
3
- module Unit
4
- module Query
5
- class TestMonetDB < MiniTest::Test
6
-
7
- describe DirectiveRecord::Query::MonetDB do
8
- before do
9
- DirectiveRecord::Query.expects(:class_for).returns(DirectiveRecord::Query::MonetDB).at_least_once
10
- end
11
-
12
- it "generates the expected SQL" do
13
- assert_equal(
14
- strip(
15
- %Q{
16
- SELECT o.id, o.city
17
- FROM offices o
18
- }
19
- ),
20
- Office.to_qry("id, city")
21
- )
22
- end
23
- end
24
-
25
- end
26
- end
27
- end