Skip to content

Commit

Permalink
Improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Jun 30, 2024
1 parent 988dba8 commit 2d61b78
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Builder/JsonOverlapsConditionBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ public function build(ExpressionInterface $expression, array &$params = []): str

$values = $this->queryBuilder->buildExpression($values, $params);

return "ARRAY(SELECT jsonb_array_elements($column::jsonb))::text[] && $values::text[]";
return "ARRAY(SELECT jsonb_array_elements_text($column::jsonb)) && $values::text[]";
}
}
10 changes: 9 additions & 1 deletion tests/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Yiisoft\Db\Exception\IntegrityException;
use Yiisoft\Db\Exception\InvalidConfigException;
use Yiisoft\Db\Exception\NotSupportedException;
use Yiisoft\Db\Expression\Expression;
use Yiisoft\Db\Expression\ExpressionInterface;
use Yiisoft\Db\Pgsql\Column;
use Yiisoft\Db\Pgsql\Tests\Support\TestTrait;
Expand Down Expand Up @@ -696,6 +697,13 @@ public function testArrayOverlapsConditionBuilder(): void
$this->assertSame('"column"::text[] && ARRAY[:qp0, :qp1, :qp2]::text[]', $sql);
$this->assertSame([':qp0' => 1, ':qp1' => 2, ':qp2' => 3], $params);

// Test column as Expression
$params = [];
$sql = $qb->buildExpression(new ArrayOverlapsCondition(new Expression('column'), [1, 2, 3]), $params);

$this->assertSame('column::text[] && ARRAY[:qp0, :qp1, :qp2]::text[]', $sql);
$this->assertSame([':qp0' => 1, ':qp1' => 2, ':qp2' => 3], $params);

$db->close();
}

Expand All @@ -708,7 +716,7 @@ public function testJsonOverlapsConditionBuilder(): void
$sql = $qb->buildExpression(new JsonOverlapsCondition('column', [1, 2, 3]), $params);

$this->assertSame(
'ARRAY(SELECT jsonb_array_elements("column"::jsonb))::text[] && ARRAY[:qp0, :qp1, :qp2]::text[]',
'ARRAY(SELECT jsonb_array_elements_text("column"::jsonb)) && ARRAY[:qp0, :qp1, :qp2]::text[]',
$sql
);
$this->assertSame([':qp0' => 1, ':qp1' => 2, ':qp2' => 3], $params);
Expand Down

0 comments on commit 2d61b78

Please sign in to comment.