sqldsl 1.4.4 → 1.4.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +14 -1
- data/lib/sql_statement.rb +14 -0
- data/lib/where_builder.rb +9 -0
- data/rakefile.rb +1 -1
- data/test/select_acceptance_test.rb +9 -0
- data/test/where_builder_test.rb +12 -12
- metadata +2 -2
data/README
CHANGED
@@ -141,6 +141,15 @@ See the tests for more examples
|
|
141
141
|
assert_equal expected.delete("\n").squeeze(" "), statement.to_sql
|
142
142
|
end
|
143
143
|
|
144
|
+
def test_add_clause
|
145
|
+
statement = Select[:column1].from[:table1].where do
|
146
|
+
like :column1, "any"
|
147
|
+
add_clause "(c2 = 'foo')"
|
148
|
+
end
|
149
|
+
assert_equal "select column1 from table1 where column1 like 'any' and (c2 = 'foo')", statement.to_sql
|
150
|
+
end
|
151
|
+
|
152
|
+
|
144
153
|
def test_select_with_receive_any_objects_and_method_calls
|
145
154
|
statement = Select[:column1, 'book', 10].from[:table1, :table2].where do
|
146
155
|
column1.equal 0
|
@@ -196,4 +205,8 @@ See the tests for more examples
|
|
196
205
|
=== Contributors
|
197
206
|
Matt[http://www.theagiledeveloper.com] Deiters[http://www.theagiledeveloper.com]
|
198
207
|
|
199
|
-
Sergio[http://spejman-on-rails.blogspot.com/] Espeja[http://spejman-on-rails.blogspot.com/]
|
208
|
+
Sergio[http://spejman-on-rails.blogspot.com/] Espeja[http://spejman-on-rails.blogspot.com/]
|
209
|
+
|
210
|
+
Pat Farley (who contributed by being sqldsl's biggest skeptic)
|
211
|
+
|
212
|
+
Clint Bishop
|
data/lib/sql_statement.rb
CHANGED
@@ -42,4 +42,18 @@ class SqlStatement
|
|
42
42
|
self
|
43
43
|
end
|
44
44
|
|
45
|
+
# call-seq: sql_statement.and_with_or_conditions { block } -> a_sql_statement
|
46
|
+
#
|
47
|
+
# Creates a new AndWithOrConditionsWhereBuilder instance, passing the block as a parameter,
|
48
|
+
# then executes to_sql on the AndWithOrConditionsWhereBuilder instance.
|
49
|
+
# The resulting string from the AndWithOrConditionsWhereBuilder instance is appended to the SQL statement.
|
50
|
+
# Returns self.
|
51
|
+
#
|
52
|
+
# Select[1].where { equal :column1, 1 }.and_with_or_conditions { equal :column2, 100 }.to_sql
|
53
|
+
# #=> "select 1 where column1 = 1 and (column2 = 100)"
|
54
|
+
def and_with_or_conditions(&block)
|
55
|
+
@to_sql += AndWithOrConditionsWhereBuilder.new(self.tables, &block).to_sql
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
45
59
|
end
|
data/lib/where_builder.rb
CHANGED
@@ -133,6 +133,15 @@ class WhereBuilder
|
|
133
133
|
" where #{sql_parts.join(' and ')}"
|
134
134
|
end
|
135
135
|
|
136
|
+
# call-seq: where.add_clause(clause)
|
137
|
+
#
|
138
|
+
# Appends a text clause to the where SQL clause.
|
139
|
+
#
|
140
|
+
# where { add_clause '(any string)' }.to_sql #=> " where (any string)"
|
141
|
+
def add_clause(arg)
|
142
|
+
sql_parts << arg
|
143
|
+
end
|
144
|
+
|
136
145
|
def add_condition(lval, operator, rval) #:nodoc:
|
137
146
|
sql_parts << "#{lval.to_sql} #{operator} #{rval.to_sql}"
|
138
147
|
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.4.
|
30
|
+
s.version = "1.4.6"
|
31
31
|
s.author = 'Jay Fields'
|
32
32
|
s.description = "A DSL for creating SQL Statements"
|
33
33
|
s.email = 'sqldsl-developer@rubyforge.org'
|
@@ -64,6 +64,15 @@ class SelectAcceptanceTest < Test::Unit::TestCase
|
|
64
64
|
assert_equal expected.delete("\n").squeeze(" "), statement.to_sql
|
65
65
|
end
|
66
66
|
|
67
|
+
def test_add_clause
|
68
|
+
statement = Select[:column1].from[:table1].where do
|
69
|
+
like :column1, "any"
|
70
|
+
add_clause "(c2 = 'foo')"
|
71
|
+
end
|
72
|
+
assert_equal "select column1 from table1 where column1 like 'any' and (c2 = 'foo')", statement.to_sql
|
73
|
+
end
|
74
|
+
|
75
|
+
|
67
76
|
def test_select_with_receive_any_objects_and_method_calls
|
68
77
|
statement = Select[:column1, 'book', 10].from[:table1, :table2].where do
|
69
78
|
column1.equal 0
|
data/test/where_builder_test.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/test_helper'
|
2
2
|
|
3
3
|
class WhereBuilderTest < Test::Unit::TestCase
|
4
|
-
|
4
|
+
|
5
5
|
def test_condition_calls_to_sql
|
6
6
|
lval, rval = mock, mock
|
7
7
|
lval.expects(:to_sql).returns "lval"
|
@@ -10,7 +10,7 @@ class WhereBuilderTest < Test::Unit::TestCase
|
|
10
10
|
where.add_condition(lval, "op", rval)
|
11
11
|
assert_equal "lval op rval", where.send(:sql_parts).first
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
def test_parenthesis_condition_calls_to_sql
|
15
15
|
lval, rval = mock, mock
|
16
16
|
lval.expects(:to_sql).returns "lval"
|
@@ -19,24 +19,24 @@ class WhereBuilderTest < Test::Unit::TestCase
|
|
19
19
|
where.add_parenthesis_condition(lval, "op", rval)
|
20
20
|
assert_equal "lval op (rval)", where.send(:sql_parts).first
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def test_method_missing_for_receive_any_creation
|
24
24
|
assert_equal ReceiveAny, WhereBuilder.new([], &lambda {}).missing_method.class
|
25
25
|
end
|
26
|
-
|
26
|
+
|
27
27
|
def test_method_missing_when_method_call_is_likely_a_mistake
|
28
28
|
assert_raises NoMethodError do
|
29
29
|
WhereBuilder.new([], &lambda {}).missing_method(:with_args)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def test_equal
|
34
34
|
statement = WhereBuilder.new [] do
|
35
35
|
equal :column1, :column2
|
36
36
|
end
|
37
37
|
assert_equal ' where column1 = column2', statement.to_sql
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
def test_not_equal
|
41
41
|
statement = WhereBuilder.new [] do
|
42
42
|
not_equal :column1, :column2
|
@@ -71,7 +71,7 @@ class WhereBuilderTest < Test::Unit::TestCase
|
|
71
71
|
end
|
72
72
|
assert_equal " where column1 < column2", statement.to_sql
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
def test_less_than_or_equal
|
76
76
|
statement = WhereBuilder.new [] do
|
77
77
|
less_than_or_equal :column1, :column2
|
@@ -85,14 +85,14 @@ class WhereBuilderTest < Test::Unit::TestCase
|
|
85
85
|
end
|
86
86
|
assert_equal " where column1 > column2", statement.to_sql
|
87
87
|
end
|
88
|
-
|
88
|
+
|
89
89
|
def test_greater_than_or_equal
|
90
90
|
statement = WhereBuilder.new [] do
|
91
91
|
greater_than_or_equal :column1, :column2
|
92
92
|
end
|
93
93
|
assert_equal " where column1 >= column2", statement.to_sql
|
94
94
|
end
|
95
|
-
|
95
|
+
|
96
96
|
def test_where_clause_is_built_with_multiple_conditions
|
97
97
|
statement = WhereBuilder.new [] do
|
98
98
|
equal :column1, :column2
|
@@ -101,21 +101,21 @@ class WhereBuilderTest < Test::Unit::TestCase
|
|
101
101
|
expected = " where column1 = column2 and column3 = column5"
|
102
102
|
assert_equal expected, statement.to_sql
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
def test_exists_evaluates_sql_statement_argument
|
106
106
|
statement = WhereBuilder.new [] do
|
107
107
|
exists Struct.new(:to_sql).new('select foo')
|
108
108
|
end
|
109
109
|
assert_equal ' where exists (select foo)', statement.to_sql
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def test_not_exists_evaluates_sql_statement_argument
|
113
113
|
statement = WhereBuilder.new [] do
|
114
114
|
not_exists Struct.new(:to_sql).new('select foo')
|
115
115
|
end
|
116
116
|
assert_equal ' where not exists (select foo)', statement.to_sql
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
def test_is_not_null_where_criteria
|
120
120
|
statement = WhereBuilder.new [] do
|
121
121
|
is_not_null Struct.new(:to_sql).new('something')
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.2
|
|
3
3
|
specification_version: 1
|
4
4
|
name: sqldsl
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.4.
|
7
|
-
date: 2007-
|
6
|
+
version: 1.4.6
|
7
|
+
date: 2007-06-25 00:00:00 -04:00
|
8
8
|
summary: A DSL for creating SQL Statements
|
9
9
|
require_paths:
|
10
10
|
- lib
|