File tree 5 files changed +60
-14
lines changed
5 files changed +60
-14
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def call
33
33
end
34
34
35
35
def `( value )
36
- Nodes ::Literal . new ( value : value )
36
+ Nodes ::Literal . new ( value : value , backend : options [ :backend ] )
37
37
end
38
38
39
39
private
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "sql/composer/nodes/core"
4
+ require "sql/composer/nodes/operators"
5
+
4
6
5
7
module SQL
6
8
module Composer
7
9
module Nodes
8
10
class Identifier < Core
11
+ include Operators
12
+
9
13
def name
10
14
fetch ( :name ) . to_s
11
15
end
@@ -29,19 +33,6 @@ def qualifier
29
33
def qualify?
30
34
options . key? ( :qualifier )
31
35
end
32
-
33
- # this is probably a stupid idea lol
34
- def ==( other )
35
- value = Nodes ::Value . new ( input : other , backend : backend )
36
-
37
- operation = Operations ::Eql . new ( left : self , right : value )
38
-
39
- if other . start_with? ( "%" ) && other . end_with? ( "%" )
40
- tokens . add ( other , value )
41
- end
42
-
43
- operation
44
- end
45
36
end
46
37
end
47
38
end
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
require "sql/composer/nodes/core"
4
+ require "sql/composer/nodes/operators"
4
5
5
6
module SQL
6
7
module Composer
7
8
module Nodes
8
9
class Literal < Core
10
+ include Operators
11
+
9
12
def value
10
13
fetch ( :value )
11
14
end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require "sql/composer/nodes/operations/eql"
4
+ require "sql/composer/nodes/operations/order_direction"
5
+
6
+ module SQL
7
+ module Composer
8
+ module Nodes
9
+ module Operators
10
+ def ==( other )
11
+ value = Nodes ::Value . new ( input : other , backend : backend )
12
+
13
+ operation = Operations ::Eql . new ( left : self , right : value )
14
+
15
+ if other . start_with? ( "%" ) && other . end_with? ( "%" )
16
+ tokens . add ( other , value )
17
+ end
18
+
19
+ operation
20
+ end
21
+
22
+ def asc
23
+ Operations ::Asc . new ( self )
24
+ end
25
+
26
+ def desc
27
+ Operations ::Desc . new ( self )
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
Original file line number Diff line number Diff line change @@ -45,6 +45,26 @@ def compose(&block)
45
45
end
46
46
end
47
47
48
+ context "with literals in WHERE" do
49
+ let ( :query ) do
50
+ compose {
51
+ SELECT `"users"."id"` , `"users"."name"`
52
+ FROM `"users"`
53
+ WHERE `"users"."name"` == 'Jane'
54
+ }
55
+ end
56
+
57
+ specify do
58
+ expect ( result ) . to eql (
59
+ <<~SQL . strip
60
+ SELECT "users"."id", "users"."name"
61
+ FROM "users"
62
+ WHERE "users"."name" == 'Jane'
63
+ SQL
64
+ )
65
+ end
66
+ end
67
+
48
68
context "inline syntax" do
49
69
let ( :query ) do
50
70
compose {
You can’t perform that action at this time.
0 commit comments