sqldsl 1.3.1 → 1.3.2

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -149,7 +149,7 @@ See the tests for more examples
149
149
 
150
150
  def test_columns_in_inner_where_are_validated_against_outer_tables
151
151
  statement = Select.all.from[:table].where do
152
- exists(Select.all.from[:inner_table => :aliased].where do
152
+ exists(Select.all.from[:inner_table.as(:aliased)].where do
153
153
  table.column1 = aliased.column1
154
154
  end)
155
155
  end
data/lib/numeric.rb CHANGED
@@ -8,7 +8,12 @@ class Numeric
8
8
  self
9
9
  end
10
10
 
11
+ # call-seq: numeric.as(alias_name) -> a_symbol
12
+ #
13
+ # Returns the number aliased (including 'as') as the aliased name
14
+ #
15
+ # 10.as(:column1) #=> :"10 as column"
11
16
  def as(alias_name)
12
- "#{self} as #{alias_name}"
17
+ "#{self} as #{alias_name}".to_sym
13
18
  end
14
19
  end
data/lib/select.rb CHANGED
@@ -45,11 +45,16 @@ class Select < SqlStatement
45
45
  #
46
46
  # Select[1, :column1, 'book'].from[:table1, :table2].to_sql #=> "select 1, column1, 'book' from table1, table2"
47
47
  def [](*table_names)
48
- @tables = table_names.inject([]) { |result, element| result + (element.is_a?(Hash) ? element.values : [element]) }
49
-
48
+ @tables = []
50
49
  @to_sql += table_names.inject([]) do |result, element|
51
- result + (element.is_a?(Symbol) ? [element] : element.to_a.inject([]) { |result, pair| result << :"#{pair.first} #{pair.last}" })
52
- end.sort{ |x,y| x.to_s <=> y.to_s }.to_sql
50
+ if element.to_s =~ / as /
51
+ @tables << element.to_s.split(/ as /).last.to_sym
52
+ result << element.to_s.gsub(/ as /, " ").to_sym
53
+ else
54
+ @tables << element
55
+ result << element
56
+ end
57
+ end.to_sql
53
58
  self
54
59
  end
55
60
 
data/lib/sqldsl.rb CHANGED
@@ -2,7 +2,6 @@ require File.dirname(__FILE__) + '/receive_any.rb'
2
2
  require File.dirname(__FILE__) + '/symbol.rb'
3
3
  require File.dirname(__FILE__) + '/array.rb'
4
4
  require File.dirname(__FILE__) + '/string.rb'
5
- require File.dirname(__FILE__) + '/hash.rb'
6
5
  require File.dirname(__FILE__) + '/numeric.rb'
7
6
  require File.dirname(__FILE__) + '/time.rb'
8
7
  require File.dirname(__FILE__) + '/sql_statement.rb'
data/lib/string.rb CHANGED
@@ -8,8 +8,13 @@ class String
8
8
  "'#{self.gsub(/'/, "''")}'"
9
9
  end
10
10
 
11
+ # call-seq: string.as(alias_name) -> a_symbol
12
+ #
13
+ # Returns the string aliased (including 'as') as the aliased name
14
+ #
15
+ # "book".as(:category) #=> :"'book' as category"
11
16
  def as(alias_name)
12
- "#{self.to_sql} as #{alias_name}"
17
+ "#{self.to_sql} as #{alias_name}".to_sym
13
18
  end
14
19
 
15
20
  end
data/lib/symbol.rb CHANGED
@@ -8,8 +8,13 @@ class Symbol
8
8
  to_s
9
9
  end
10
10
 
11
+ # call-seq: symbol.as(alias_name) -> a_symbol
12
+ #
13
+ # Returns the symbol aliased (including 'as') as the aliased name
14
+ #
15
+ # :book.as(:category) #=> :"book as category"
11
16
  def as(alias_name)
12
- "#{self} as #{alias_name}"
17
+ "#{self} as #{alias_name}".to_sym
13
18
  end
14
19
 
15
20
  end
data/rakefile.rb CHANGED
@@ -27,7 +27,7 @@ Gem::manage_gems
27
27
  specification = Gem::Specification.new do |s|
28
28
  s.name = "sqldsl"
29
29
  s.summary = "A DSL for creating SQL Statements"
30
- s.version = "1.3.1"
30
+ s.version = "1.3.2"
31
31
  s.author = 'Jay Fields'
32
32
  s.description = "A DSL for creating SQL Statements"
33
33
  s.email = 'sqldsl-developer@rubyforge.org'
data/test/numeric_test.rb CHANGED
@@ -6,6 +6,6 @@ class NumbericTest < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  def test_as
9
- assert_equal '1 as bam', 1.as(:bam)
9
+ assert_equal :'1 as bam', 1.as(:bam)
10
10
  end
11
11
  end
@@ -73,7 +73,7 @@ class SelectAcceptanceTest < Test::Unit::TestCase
73
73
 
74
74
  def test_columns_in_inner_where_are_validated_against_outer_tables
75
75
  statement = Select.all.from[:table].where do
76
- exists(Select.all.from[:inner_table => :aliased].where do
76
+ exists(Select.all.from[:inner_table.as(:aliased)].where do
77
77
  table.column1 = aliased.column1
78
78
  end)
79
79
  end
data/test/select_test.rb CHANGED
@@ -23,7 +23,7 @@ class SelectTest < Test::Unit::TestCase
23
23
  end
24
24
 
25
25
  def test_select_with_multiple_tables
26
- assert_equal 'select column from bar, foo', Select[:column].from[:foo, :bar].to_sql
26
+ assert_equal 'select column from foo, bar', Select[:column].from[:foo, :bar].to_sql
27
27
  end
28
28
 
29
29
  def test_order_by
@@ -39,11 +39,11 @@ class SelectTest < Test::Unit::TestCase
39
39
  end
40
40
 
41
41
  def test_column_aliasing
42
- assert_equal 'select column1 as foo, column2 as bar', Select[:column1 => :foo, :column2 => :bar].to_sql
42
+ assert_equal "select column1 as foo, 2 as bar, 'foo' as baz", Select[:column1.as(:foo), 2.as(:bar), 'foo'.as(:baz)].to_sql
43
43
  end
44
44
 
45
45
  def test_table_aliasing
46
- assert_equal 'select * from table1 foo, table2 bar', Select.all.from[:table1 => :foo, :table2 => :bar].to_sql
46
+ assert_equal 'select * from table1 foo, table2 bar, table3', Select.all.from[:table1.as(:foo), :table2.as(:bar), :table3].to_sql
47
47
  end
48
48
 
49
49
  def test_tables_no_aliasing
data/test/string_test.rb CHANGED
@@ -10,6 +10,6 @@ class StringTest < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  def test_as
13
- assert_equal "'foo' as bar", "foo".as(:bar)
13
+ assert_equal :"'foo' as bar", "foo".as(:bar)
14
14
  end
15
15
  end
data/test/symbol_test.rb CHANGED
@@ -6,6 +6,6 @@ class SymbolTest < Test::Unit::TestCase
6
6
  end
7
7
 
8
8
  def test_as
9
- assert_equal 'asdf as bam', :asdf.as(:bam)
9
+ assert_equal :'asdf as bam', :asdf.as(:bam)
10
10
  end
11
11
  end
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: sqldsl
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.3.1
7
- date: 2007-03-14 00:00:00 -04:00
6
+ version: 1.3.2
7
+ date: 2007-03-16 00:00:00 -04:00
8
8
  summary: A DSL for creating SQL Statements
9
9
  require_paths:
10
10
  - lib
@@ -31,7 +31,6 @@ files:
31
31
  - lib/array.rb
32
32
  - lib/delete.rb
33
33
  - lib/distinct_select.rb
34
- - lib/hash.rb
35
34
  - lib/insert.rb
36
35
  - lib/numeric.rb
37
36
  - lib/or_where_builder.rb
@@ -48,7 +47,6 @@ files:
48
47
  - test/array_test.rb
49
48
  - test/delete_acceptance_test.rb
50
49
  - test/delete_test.rb
51
- - test/hash_test.rb
52
50
  - test/insert_acceptance_test.rb
53
51
  - test/insert_test.rb
54
52
  - test/numeric_test.rb
data/lib/hash.rb DELETED
@@ -1,16 +0,0 @@
1
- class Hash
2
-
3
- # call-seq: hash.to_sql -> a_string
4
- #
5
- # Returns a string with single quotes escaped.
6
- #
7
- # {:column1 => :foo, :column2 => :bar}.to_sql #=> "column1 as foo, column2 as bar"
8
- def to_sql
9
- result = []
10
- each_pair do |key, value|
11
- result << "#{key} as #{value}".to_sym
12
- end
13
- result.sort{ |x,y| x.to_s <=> y.to_s }.to_sql
14
- end
15
-
16
- end
data/test/hash_test.rb DELETED
@@ -1,9 +0,0 @@
1
- require File.dirname(__FILE__) + '/test_helper'
2
-
3
- class HashTest < Test::Unit::TestCase
4
-
5
- def test_to_sql_name_value_as_aliasing
6
- assert_equal "a as b, c as d", {:a => :b, :c => :d}.to_sql
7
- end
8
-
9
- end