Skip to content

Commit 01de3cf

Browse files
committed
AND NOT and OR NOT
1 parent 41a192c commit 01de3cf

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

src/Syntax/Where.php

+46-40
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace NilPortugues\Sql\QueryBuilder\Syntax;
1212

13-
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface;
1413
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryException;
1514
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryFactory;
15+
use NilPortugues\Sql\QueryBuilder\Manipulation\QueryInterface;
1616
use NilPortugues\Sql\QueryBuilder\Manipulation\Select;
1717

1818
/**
@@ -29,7 +29,9 @@ class Where
2929
const OPERATOR_EQUAL = '=';
3030
const OPERATOR_NOT_EQUAL = '<>';
3131
const CONJUNCTION_AND = 'AND';
32+
const CONJUNCTION_AND_NOT = 'AND NOT';
3233
const CONJUNCTION_OR = 'OR';
34+
const CONJUNCTION_OR_NOT = 'OR NOT';
3335
const CONJUNCTION_EXISTS = 'EXISTS';
3436
const CONJUNCTION_NOT_EXISTS = 'NOT EXISTS';
3537

@@ -149,6 +151,29 @@ public function getConjunction()
149151
return $this->conjunction;
150152
}
151153

154+
/**
155+
* @param string $operator
156+
*
157+
* @return $this
158+
*
159+
* @throws QueryException
160+
*/
161+
public function conjunction($operator)
162+
{
163+
if (false === \in_array(
164+
$operator,
165+
[self::CONJUNCTION_AND, self::CONJUNCTION_OR, self::CONJUNCTION_OR_NOT, self::CONJUNCTION_AND_NOT]
166+
)
167+
) {
168+
throw new QueryException(
169+
"Invalid conjunction specified, must be one of AND or OR, but '".$operator."' was found."
170+
);
171+
}
172+
$this->conjunction = $operator;
173+
174+
return $this;
175+
}
176+
152177
/**
153178
* @return array
154179
*/
@@ -174,25 +199,6 @@ public function subWhere($operator = 'OR')
174199
return $filter;
175200
}
176201

177-
/**
178-
* @param string $operator
179-
*
180-
* @return $this
181-
*
182-
* @throws QueryException
183-
*/
184-
public function conjunction($operator)
185-
{
186-
if (false === \in_array($operator, [self::CONJUNCTION_AND, self::CONJUNCTION_OR])) {
187-
throw new QueryException(
188-
"Invalid conjunction specified, must be one of AND or OR, but '".$operator."' was found."
189-
);
190-
}
191-
$this->conjunction = $operator;
192-
193-
return $this;
194-
}
195-
196202
/**
197203
* @return Table
198204
*/
@@ -218,7 +224,7 @@ public function setTable($table)
218224
/**
219225
* equals alias.
220226
*
221-
* @param $column
227+
* @param $column
222228
* @param int $value
223229
*
224230
* @return static
@@ -240,8 +246,8 @@ public function equals($column, $value)
240246
}
241247

242248
/**
243-
* @param $column
244-
* @param $value
249+
* @param $column
250+
* @param $value
245251
* @param string $operator
246252
*
247253
* @return $this
@@ -333,7 +339,7 @@ public function lessThanOrEqual($column, $value)
333339

334340
/**
335341
* @param string $column
336-
* @param $value
342+
* @param $value
337343
*
338344
* @return static
339345
*/
@@ -509,6 +515,14 @@ public function exists(Select $select)
509515
return $this;
510516
}
511517

518+
/**
519+
* @return array
520+
*/
521+
public function getExists()
522+
{
523+
return $this->exists;
524+
}
525+
512526
/**
513527
* @param Select $select
514528
*
@@ -521,6 +535,14 @@ public function notExists(Select $select)
521535
return $this;
522536
}
523537

538+
/**
539+
* @return array
540+
*/
541+
public function getNotExists()
542+
{
543+
return $this->notExists;
544+
}
545+
524546
/**
525547
* @return array
526548
*/
@@ -584,20 +606,4 @@ public function getNull()
584606
{
585607
return $this->isNull;
586608
}
587-
588-
/**
589-
* @return array
590-
*/
591-
public function getExists()
592-
{
593-
return $this->exists;
594-
}
595-
596-
/**
597-
* @return array
598-
*/
599-
public function getNotExists()
600-
{
601-
return $this->notExists;
602-
}
603609
}

0 commit comments

Comments
 (0)