-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add json overlaps condition builders
- Loading branch information
Showing
4 changed files
with
108 additions
and
0 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,44 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Builder; | ||
|
||
use Yiisoft\Db\Exception\Exception; | ||
use Yiisoft\Db\Exception\InvalidArgumentException; | ||
use Yiisoft\Db\Exception\InvalidConfigException; | ||
use Yiisoft\Db\Exception\NotSupportedException; | ||
use Yiisoft\Db\Expression\ExpressionInterface; | ||
use Yiisoft\Db\Expression\JsonExpression; | ||
use Yiisoft\Db\QueryBuilder\Condition\Builder\AbstractOverlapsConditionBuilder; | ||
use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition; | ||
|
||
/** | ||
* Builds expressions for {@see JsonOverlapsCondition} for SQLite Server. | ||
*/ | ||
final class JsonOverlapsConditionBuilder extends AbstractOverlapsConditionBuilder | ||
{ | ||
/** | ||
* Build SQL for {@see JsonOverlapsCondition}. | ||
* | ||
* @param JsonOverlapsCondition $expression the {@see JsonOverlapsCondition} to be built. | ||
* | ||
* @throws Exception | ||
* @throws InvalidArgumentException | ||
* @throws InvalidConfigException | ||
* @throws NotSupportedException | ||
*/ | ||
public function build(ExpressionInterface $expression, array &$params = []): string | ||
{ | ||
$column = $this->prepareColumn($expression->getColumn()); | ||
$values = $expression->getValues(); | ||
|
||
if (!$values instanceof ExpressionInterface) { | ||
$values = new JsonExpression($values); | ||
} | ||
|
||
$values = $this->queryBuilder->buildExpression($values, $params); | ||
|
||
return "EXISTS(SELECT value FROM json_each($column) INTERSECT SELECT value FROM json_each($values))=1"; | ||
} | ||
} |
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
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