Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
347 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Yiisoft\Db\Sqlite\Builder; | ||
|
||
use JsonException; | ||
use Yiisoft\Db\Exception\Exception; | ||
use Yiisoft\Db\Exception\InvalidArgumentException; | ||
use Yiisoft\Db\Exception\InvalidConfigException; | ||
use Yiisoft\Db\Exception\NotSupportedException; | ||
use Yiisoft\Db\Expression\ExpressionBuilderInterface; | ||
use Yiisoft\Db\Expression\ExpressionInterface; | ||
use Yiisoft\Db\Expression\JsonExpression; | ||
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface; | ||
use Yiisoft\Db\Query\QueryInterface; | ||
use Yiisoft\Json\Json; | ||
|
||
/** | ||
* Builds expressions for {@see `Yiisoft\Db\Expression\JsonExpression`} for SQLite. | ||
*/ | ||
final class JsonExpressionBuilder implements ExpressionBuilderInterface | ||
{ | ||
public function __construct(private QueryBuilderInterface $queryBuilder) | ||
{ | ||
} | ||
|
||
/** | ||
* The method builds the raw SQL from the `$expression` that won't be additionally escaped or quoted. | ||
* | ||
* @param JsonExpression $expression The expression to build. | ||
* @param array $params The binding parameters. | ||
* | ||
* @throws Exception | ||
* @throws InvalidArgumentException | ||
* @throws InvalidConfigException | ||
* @throws JsonException | ||
* @throws NotSupportedException | ||
* | ||
* @return string The raw SQL that won't be additionally escaped or quoted. | ||
*/ | ||
public function build(ExpressionInterface $expression, array &$params = []): string | ||
{ | ||
/** @psalm-var mixed $value */ | ||
$value = $expression->getValue(); | ||
|
||
if ($value instanceof QueryInterface) { | ||
[$sql, $params] = $this->queryBuilder->build($value, $params); | ||
|
||
return "($sql)"; | ||
} | ||
|
||
return $this->queryBuilder->bindParam(Json::encode($value), $params); | ||
} | ||
} |
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
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
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.