File tree Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Expand file tree Collapse file tree 3 files changed +27
-1
lines changed Original file line number Diff line number Diff line change @@ -348,7 +348,8 @@ protected function compileComparison(ComparisonOperationInterface $expr): string
348348
349349 protected function compileRelationalExpression (RelationalExpression $ expr ): string
350350 {
351- $ output = $ this ->compileComparable ($ expr ->getOperand1 ());
351+ $ output = $ expr ->isNegated () ? 'NOT ' : '' ;
352+ $ output .= $ this ->compileComparable ($ expr ->getOperand1 ());
352353 $ output .= $ this ->compileRelationalOperator ($ expr ->getOperator ());
353354 $ output .= $ this ->compileComparable ($ expr ->getOperand2 ());
354355 return $ output ;
Original file line number Diff line number Diff line change 33namespace Francerz \SqlBuilder \Expressions \Comparison ;
44
55use Francerz \SqlBuilder \Expressions \ComparableComponentInterface ;
6+ use Francerz \SqlBuilder \Expressions \NegatableInterface ;
67use Francerz \SqlBuilder \Expressions \TwoOperandsInterface ;
78use Francerz \SqlBuilder \Nesting \NestOperationResolverInterface ;
89use Francerz \SqlBuilder \Nesting \NestTranslator ;
1415class RelationalExpression implements
1516 ComparisonOperationInterface,
1617 TwoOperandsInterface,
18+ NegatableInterface,
1719 NestOperationResolverInterface
1820{
1921
2022 private $ operand1 ;
2123 private $ operand2 ;
2224 private $ operator ;
2325
26+ private $ negated = false ;
27+
2428 public function __construct (
2529 ComparableComponentInterface $ operand1 ,
2630 ComparableComponentInterface $ operand2 ,
@@ -66,6 +70,16 @@ public function getOperator()
6670 return $ this ->operator ;
6771 }
6872
73+ public function negate (bool $ negate = true )
74+ {
75+ $ this ->negated = $ negate ;
76+ }
77+
78+ public function isNegated (): bool
79+ {
80+ return $ this ->negated ;
81+ }
82+
6983 public function requiresTransform (): bool
7084 {
7185 return $ this ->operand1 instanceof ValueProxy || $ this ->operand2 instanceof ValueProxy;
Original file line number Diff line number Diff line change @@ -157,4 +157,15 @@ public function testWhereArgs()
157157
158158 $ this ->assertEquals ($ expected , $ compiled ->getQuery ());
159159 }
160+
161+ public function testWhereNot ()
162+ {
163+ $ query = Query::selectFrom (['groups ' ]);
164+ $ query ->where ()->not ('group_id ' , 1 );
165+
166+ $ compiled = $ this ->compiler ->compileSelect ($ query );
167+
168+ $ expected = "SELECT groups.* FROM groups WHERE NOT group_id = :v1 " ;
169+ $ this ->assertEquals ($ expected , $ compiled ->getQuery ());
170+ }
160171}
You can’t perform that action at this time.
0 commit comments