arel 0.2.pre → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -3
- data/Thorfile +1 -1
- data/arel.gemspec +3 -3
- data/lib/arel.rb +1 -1
- data/lib/arel/algebra/relations/operations/join.rb +4 -0
- data/lib/arel/engines/sql/core_extensions/array.rb +5 -1
- data/lib/arel/engines/sql/engine.rb +4 -0
- data/lib/arel/engines/sql/relations/table.rb +4 -3
- data/spec/arel/engines/sql/unit/predicates/in_spec.rb +19 -0
- data/spec/arel/engines/sql/unit/relations/join_spec.rb +30 -1
- data/spec/arel/engines/sql/unit/relations/table_spec.rb +19 -0
- metadata +4 -4
data/History.txt
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
==
|
2
|
-
|
3
|
-
* 1 major enhancement
|
1
|
+
== 0.2.0 / 2010-01-31
|
4
2
|
|
5
3
|
* Ruby 1.9 compatibility
|
4
|
+
* Many improvements to support the Arel integration into ActiveRecord (see `git log v0.1.0..v0.2.0`)
|
5
|
+
* Thanks to Emilio Tagua and Pratik Naik for many significant contributions!
|
6
6
|
|
7
7
|
== 0.1.0 / 2009-08-06
|
8
8
|
|
data/Thorfile
CHANGED
data/arel.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{arel}
|
5
|
-
s.version = "0.2.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Bryan Helmkamp", "Nick Kallen"]
|
9
|
-
s.date = %q{2010-01-
|
9
|
+
s.date = %q{2010-01-31}
|
10
10
|
s.description = %q{Arel is a Relational Algebra for Ruby. It 1) simplifies the generation complex
|
11
11
|
of SQL queries and it 2) adapts to various RDBMS systems. It is intended to be
|
12
12
|
a framework framework; that is, you can build your own ORM with it, focusing on
|
data/lib/arel.rb
CHANGED
@@ -2,7 +2,11 @@ module Arel
|
|
2
2
|
module Sql
|
3
3
|
module ArrayExtensions
|
4
4
|
def to_sql(formatter = nil)
|
5
|
-
|
5
|
+
if any?
|
6
|
+
"(" + collect { |e| e.to_sql(formatter) }.join(', ') + ")"
|
7
|
+
else
|
8
|
+
"(NULL)"
|
9
|
+
end
|
6
10
|
end
|
7
11
|
|
8
12
|
def inclusion_predicate_sql
|
@@ -11,7 +11,7 @@ module Arel
|
|
11
11
|
if options.is_a?(Hash)
|
12
12
|
@options = options
|
13
13
|
@engine = options[:engine] || Table.engine
|
14
|
-
@table_alias = options[:as].to_s if options[:as].present?
|
14
|
+
@table_alias = options[:as].to_s if options[:as].present? && options[:as].to_s != @name
|
15
15
|
else
|
16
16
|
@engine = options # Table.new('foo', engine)
|
17
17
|
end
|
@@ -52,8 +52,9 @@ module Arel
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def ==(other)
|
55
|
-
Table
|
56
|
-
name
|
55
|
+
Table === other and
|
56
|
+
name == other.name and
|
57
|
+
table_alias == other.table_alias
|
57
58
|
end
|
58
59
|
end
|
59
60
|
end
|
@@ -45,6 +45,25 @@ module Arel
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
48
|
+
|
49
|
+
describe 'when the array is empty' do
|
50
|
+
before do
|
51
|
+
@array = []
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'manufactures sql with a comma separated list' do
|
55
|
+
sql = In.new(@attribute, @array).to_sql
|
56
|
+
|
57
|
+
adapter_is :mysql do
|
58
|
+
sql.should be_like(%Q{`users`.`id` IN (NULL)})
|
59
|
+
end
|
60
|
+
|
61
|
+
adapter_is_not :mysql do
|
62
|
+
sql.should be_like(%Q{"users"."id" IN (NULL)})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
48
67
|
end
|
49
68
|
|
50
69
|
describe 'when relating to a range' do
|
@@ -103,7 +103,36 @@ module Arel
|
|
103
103
|
})
|
104
104
|
end
|
105
105
|
end
|
106
|
-
|
106
|
+
|
107
|
+
it "passes the string when there are multiple string joins" do
|
108
|
+
relation = StringJoin.new(@relation1, "INNER JOIN asdf ON fdsa")
|
109
|
+
relation = StringJoin.new(relation, "INNER JOIN lifo ON fifo")
|
110
|
+
sql = StringJoin.new(relation, "INNER JOIN hatful ON hallow").to_sql
|
111
|
+
|
112
|
+
adapter_is :mysql do
|
113
|
+
sql.should be_like(%Q{
|
114
|
+
SELECT `users`.`id`, `users`.`name`
|
115
|
+
FROM `users`
|
116
|
+
INNER JOIN asdf ON fdsa
|
117
|
+
INNER JOIN lifo ON fifo
|
118
|
+
INNER JOIN hatful ON hallow
|
119
|
+
})
|
120
|
+
end
|
121
|
+
|
122
|
+
adapter_is_not :mysql do
|
123
|
+
sql.should be_like(%Q{
|
124
|
+
SELECT "users"."id", "users"."name"
|
125
|
+
FROM "users"
|
126
|
+
INNER JOIN asdf ON fdsa
|
127
|
+
INNER JOIN lifo ON fifo
|
128
|
+
INNER JOIN hatful ON hallow
|
129
|
+
})
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
|
107
136
|
end
|
108
137
|
end
|
109
138
|
end
|
@@ -44,6 +44,25 @@ module Arel
|
|
44
44
|
})
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
it "does not apply alias if it's same as the table name" do
|
49
|
+
sql = @relation.as(:users).to_sql
|
50
|
+
|
51
|
+
adapter_is :mysql do
|
52
|
+
sql.should be_like(%Q{
|
53
|
+
SELECT `users`.`id`, `users`.`name`
|
54
|
+
FROM `users`
|
55
|
+
})
|
56
|
+
end
|
57
|
+
|
58
|
+
adapter_is_not :mysql do
|
59
|
+
sql.should be_like(%Q{
|
60
|
+
SELECT "users"."id", "users"."name"
|
61
|
+
FROM "users"
|
62
|
+
})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
47
66
|
end
|
48
67
|
|
49
68
|
describe '#column_for' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: arel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2010-01-
|
13
|
+
date: 2010-01-31 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -194,9 +194,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
194
194
|
version:
|
195
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
196
196
|
requirements:
|
197
|
-
- - "
|
197
|
+
- - ">="
|
198
198
|
- !ruby/object:Gem::Version
|
199
|
-
version:
|
199
|
+
version: "0"
|
200
200
|
version:
|
201
201
|
requirements: []
|
202
202
|
|