File tree Expand file tree Collapse file tree 5 files changed +60
-14
lines changed
Expand file tree Collapse file tree 5 files changed +60
-14
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ def call
3333 end
3434
3535 def `( value )
36- Nodes ::Literal . new ( value : value )
36+ Nodes ::Literal . new ( value : value , backend : options [ :backend ] )
3737 end
3838
3939 private
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33require "sql/composer/nodes/core"
4+ require "sql/composer/nodes/operators"
5+
46
57module SQL
68 module Composer
79 module Nodes
810 class Identifier < Core
11+ include Operators
12+
913 def name
1014 fetch ( :name ) . to_s
1115 end
@@ -29,19 +33,6 @@ def qualifier
2933 def qualify?
3034 options . key? ( :qualifier )
3135 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
4536 end
4637 end
4738 end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33require "sql/composer/nodes/core"
4+ require "sql/composer/nodes/operators"
45
56module SQL
67 module Composer
78 module Nodes
89 class Literal < Core
10+ include Operators
11+
912 def value
1013 fetch ( :value )
1114 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)
4545 end
4646 end
4747
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+
4868 context "inline syntax" do
4969 let ( :query ) do
5070 compose {
You can’t perform that action at this time.
0 commit comments