sqldsl 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README CHANGED
@@ -143,7 +143,7 @@ See the tests for more examples
143
143
  end.or do
144
144
  column1 > 100
145
145
  end
146
- expected = "select column1, 'book', 10 from table1, table2 where column1 = 0 or column1 > 100"
146
+ expected = "select column1, 'book', 10 from table1, table2 where column1 = 0 or (column1 > 100)"
147
147
  assert_equal expected, statement.to_sql
148
148
  end
149
149
 
data/lib/numeric.rb CHANGED
@@ -7,4 +7,8 @@ class Numeric
7
7
  def to_sql
8
8
  self
9
9
  end
10
+
11
+ def as(alias_name)
12
+ "#{self} as #{alias_name}"
13
+ end
10
14
  end
@@ -7,9 +7,9 @@ class OrWhereBuilder < WhereBuilder
7
7
  # OrWhereBuilder.new [] do
8
8
  # equal :column1, 10
9
9
  # equal :column2, 'book'
10
- # end.to_sql #=> " or column1 = 10 and column2 = 'book'"
10
+ # end.to_sql #=> " or (column1 = 10 and column2 = 'book')"
11
11
  def to_sql
12
- " or #{sql_parts.join(' and ')}"
12
+ " or (#{sql_parts.join(' and ')})"
13
13
  end
14
14
 
15
15
  end
data/lib/select.rb CHANGED
@@ -18,7 +18,7 @@ class Select < SqlStatement
18
18
  DistinctSelect
19
19
  end
20
20
 
21
- # call-seq: Select[arg,...] -> a_select
21
+ # call-seq: Select.all -> a_select
22
22
  #
23
23
  # Returns a Select instance with the SQL initialized to 'select *'
24
24
  #
data/lib/string.rb CHANGED
@@ -7,5 +7,9 @@ class String
7
7
  def to_sql
8
8
  "'#{self.gsub(/'/, "''")}'"
9
9
  end
10
+
11
+ def as(alias_name)
12
+ "#{self.to_sql} as #{alias_name}"
13
+ end
10
14
 
11
15
  end
data/lib/symbol.rb CHANGED
@@ -6,6 +6,10 @@ class Symbol
6
6
  # "it's".to_sql #=> "'it''s'"
7
7
  def to_sql
8
8
  to_s
9
- end
9
+ end
10
+
11
+ def as(alias_name)
12
+ "#{self} as #{alias_name}"
13
+ end
10
14
 
11
15
  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.0"
30
+ s.version = "1.3.1"
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
@@ -4,4 +4,8 @@ class NumbericTest < Test::Unit::TestCase
4
4
  def test_to_sql_gives_self
5
5
  assert_equal 123, 123.to_sql
6
6
  end
7
+
8
+ def test_as
9
+ assert_equal '1 as bam', 1.as(:bam)
10
+ end
7
11
  end
@@ -67,7 +67,7 @@ class SelectAcceptanceTest < Test::Unit::TestCase
67
67
  end.or do
68
68
  column1 > 100
69
69
  end
70
- expected = "select column1, 'book', 10 from table1, table2 where column1 = 0 or column1 > 100"
70
+ expected = "select column1, 'book', 10 from table1, table2 where column1 = 0 or (column1 > 100)"
71
71
  assert_equal expected, statement.to_sql
72
72
  end
73
73
 
data/test/string_test.rb CHANGED
@@ -8,4 +8,8 @@ class StringTest < Test::Unit::TestCase
8
8
  def test_to_sql_gives_quoted_and_escapes_single_quotes
9
9
  assert_equal "'it''s'", "it's".to_sql
10
10
  end
11
+
12
+ def test_as
13
+ assert_equal "'foo' as bar", "foo".as(:bar)
14
+ end
11
15
  end
data/test/symbol_test.rb CHANGED
@@ -4,4 +4,8 @@ class SymbolTest < Test::Unit::TestCase
4
4
  def test_to_sql_returns_to_s
5
5
  assert_equal 'asdf', :asdf.to_sql
6
6
  end
7
+
8
+ def test_as
9
+ assert_equal 'asdf as bam', :asdf.as(:bam)
10
+ end
7
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.0
7
- date: 2007-03-11 00:00:00 -05:00
6
+ version: 1.3.1
7
+ date: 2007-03-14 00:00:00 -04:00
8
8
  summary: A DSL for creating SQL Statements
9
9
  require_paths:
10
10
  - lib