Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A few more Conditions and methods in GenericTableGateway to create them
- Loading branch information
1 parent
9d5cbc0
commit 70703f2
Showing
6 changed files
with
479 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sad_spirit/pg_gateway package | ||
* | ||
* (c) Alexey Borzov <avb@php.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace sad_spirit\pg_gateway\conditions\column; | ||
|
||
use sad_spirit\pg_gateway\TableGateway; | ||
use sad_spirit\pg_builder\nodes\{ | ||
ColumnReference, | ||
ScalarExpression, | ||
expressions\ArrayComparisonExpression, | ||
expressions\NamedParameter, | ||
expressions\OperatorExpression, | ||
expressions\TypecastExpression | ||
}; | ||
|
||
/** | ||
* Generates a "foo = any(:foo::foo_type[])" condition for the "foo" table column | ||
*/ | ||
final class AnyCondition extends TypedCondition | ||
{ | ||
protected function generateExpressionImpl(): ScalarExpression | ||
{ | ||
$typeName = $this->converterFactory->createTypeNameNodeForOID($this->column->getTypeOID()); | ||
$typeName->bounds = [-1]; | ||
|
||
return new OperatorExpression( | ||
'=', | ||
new ColumnReference(TableGateway::ALIAS_SELF, $this->column->getName()), | ||
new ArrayComparisonExpression( | ||
ArrayComparisonExpression::ANY, | ||
new TypecastExpression(new NamedParameter($this->column->getName()), $typeName) | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sad_spirit/pg_gateway package | ||
* | ||
* (c) Alexey Borzov <avb@php.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace sad_spirit\pg_gateway\conditions\column; | ||
|
||
use sad_spirit\pg_gateway\{ | ||
TableGateway, | ||
conditions\ColumnCondition, | ||
exceptions\LogicException, | ||
metadata\Column | ||
}; | ||
use sad_spirit\pg_builder\nodes\ColumnReference; | ||
use sad_spirit\pg_builder\nodes\ScalarExpression; | ||
|
||
/** | ||
* Uses the value of the bool-typed column as a Condition | ||
*/ | ||
final class BoolCondition extends ColumnCondition | ||
{ | ||
public const BOOL_OID = 16; | ||
|
||
public function __construct(Column $column) | ||
{ | ||
if (self::BOOL_OID !== (int)$column->getTypeOID()) { | ||
throw new LogicException("Column '{$column->getName()}' is not of type 'bool'"); | ||
} | ||
parent::__construct($column); | ||
} | ||
|
||
protected function generateExpressionImpl(): ScalarExpression | ||
{ | ||
return new ColumnReference(TableGateway::ALIAS_SELF, $this->column->getName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of sad_spirit/pg_gateway package | ||
* | ||
* (c) Alexey Borzov <avb@php.net> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace sad_spirit\pg_gateway\conditions\column; | ||
|
||
use sad_spirit\pg_gateway\TableGateway; | ||
use sad_spirit\pg_gateway\conditions\ColumnCondition; | ||
use sad_spirit\pg_builder\nodes\{ | ||
ColumnReference, | ||
ScalarExpression, | ||
expressions\IsExpression | ||
}; | ||
|
||
/** | ||
* Generates a "foo IS [NOT] NULL" Condition for the "foo" table column | ||
*/ | ||
final class IsNullCondition extends ColumnCondition | ||
{ | ||
protected function generateExpressionImpl(): ScalarExpression | ||
{ | ||
return new IsExpression( | ||
new ColumnReference(TableGateway::ALIAS_SELF, $this->column->getName()), | ||
IsExpression::NULL | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.