aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/sql_algebra.rb1
-rw-r--r--lib/sql_algebra/relations/attribute.rb4
-rw-r--r--lib/sql_algebra/relations/relation.rb4
-rw-r--r--spec/relations/attribute_spec.rb6
-rw-r--r--spec/relations/relation_spec.rb6
-rw-r--r--spec/relations/table_relation_spec.rb24
6 files changed, 37 insertions, 8 deletions
diff --git a/lib/sql_algebra.rb b/lib/sql_algebra.rb
index b3e3c8d176..61625ff270 100644
--- a/lib/sql_algebra.rb
+++ b/lib/sql_algebra.rb
@@ -17,6 +17,7 @@ require 'sql_algebra/relations/projection_relation'
require 'sql_algebra/relations/selection_relation'
require 'sql_algebra/relations/order_relation'
require 'sql_algebra/relations/range_relation'
+require 'sql_algebra/relations/rename_relation'
require 'sql_algebra/relations/join'
require 'sql_algebra/predicates/predicate'
diff --git a/lib/sql_algebra/relations/attribute.rb b/lib/sql_algebra/relations/attribute.rb
index 85d40dfb12..89ac495245 100644
--- a/lib/sql_algebra/relations/attribute.rb
+++ b/lib/sql_algebra/relations/attribute.rb
@@ -5,6 +5,10 @@ class Attribute
@relation, @attribute_name, @aliaz = relation, attribute_name, aliaz
end
+ def aliazz(aliaz)
+ Attribute.new(relation, attribute_name, aliaz)
+ end
+
def eql?(other)
relation == other.relation and attribute_name == other.attribute_name
end
diff --git a/lib/sql_algebra/relations/relation.rb b/lib/sql_algebra/relations/relation.rb
index 8c21927d01..02723ae0cc 100644
--- a/lib/sql_algebra/relations/relation.rb
+++ b/lib/sql_algebra/relations/relation.rb
@@ -32,6 +32,10 @@ class Relation
def order(*attributes)
OrderRelation.new(self, *attributes)
end
+
+ def rename(attribute, aliaz)
+ RenameRelation.new(self, attribute, aliaz)
+ end
end
include Operations
diff --git a/spec/relations/attribute_spec.rb b/spec/relations/attribute_spec.rb
index d8a007f918..7015fd2542 100644
--- a/spec/relations/attribute_spec.rb
+++ b/spec/relations/attribute_spec.rb
@@ -6,6 +6,12 @@ describe Attribute do
@relation2 = TableRelation.new(:bar)
end
+ describe 'aliaz' do
+ it "manufactures an aliased attributed" do
+ pending
+ end
+ end
+
describe '#eql?' do
it "obtains if the relation and attribute name are identical" do
Attribute.new(@relation1, :attribute_name).should be_eql(Attribute.new(@relation1, :attribute_name))
diff --git a/spec/relations/relation_spec.rb b/spec/relations/relation_spec.rb
index db4b6b8775..5cef7d7b3d 100644
--- a/spec/relations/relation_spec.rb
+++ b/spec/relations/relation_spec.rb
@@ -48,6 +48,12 @@ describe Relation do
end
end
+ describe Relation, '#rename' do
+ it "manufactures a rename relation" do
+ @relation1.rename(@attribute1, :foo).should == RenameRelation.new(@relation1, @attribute1, :foo)
+ end
+ end
+
describe Relation, '#select' do
before do
@predicate = EqualityPredicate.new(@attribute1, @attribute2)
diff --git a/spec/relations/table_relation_spec.rb b/spec/relations/table_relation_spec.rb
index 8cd31a9ac8..dec8bba6b1 100644
--- a/spec/relations/table_relation_spec.rb
+++ b/spec/relations/table_relation_spec.rb
@@ -1,13 +1,21 @@
require File.join(File.dirname(__FILE__), '..', 'spec_helper')
-describe TableRelation, '#to_sql' do
- it "returns a simple SELECT query" do
- TableRelation.new(:users).to_sql.should == SelectBuilder.new do |s|
- select do
- column :users, :name
- column :users, :id
+describe TableRelation do
+ describe '#to_sql' do
+ it "returns a simple SELECT query" do
+ TableRelation.new(:users).to_sql.should == SelectBuilder.new do |s|
+ select do
+ column :users, :name
+ column :users, :id
+ end
+ from :users
end
- from :users
end
end
-end
+
+ describe '#attributes' do
+ it 'manufactures attributes corresponding to columns in the table' do
+ pending
+ end
+ end
+end \ No newline at end of file