From 966a4c2e7739423f8644114e55ab7489d183caad Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sun, 3 Aug 2025 01:31:06 +0300 Subject: [PATCH 1/5] Support `StringableStream` instances --- src/Column/BinaryColumn.php | 5 +++-- tests/ColumnTest.php | 2 +- tests/Provider/QueryBuilderProvider.php | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Column/BinaryColumn.php b/src/Column/BinaryColumn.php index f546f933a..306b9628e 100644 --- a/src/Column/BinaryColumn.php +++ b/src/Column/BinaryColumn.php @@ -5,6 +5,7 @@ namespace Yiisoft\Db\Pgsql\Column; use Yiisoft\Db\Schema\Column\BinaryColumn as BaseBinaryColumn; +use Yiisoft\Db\Schema\Data\StringableStream; use function hex2bin; use function is_string; @@ -13,12 +14,12 @@ final class BinaryColumn extends BaseBinaryColumn { - public function phpTypecast(mixed $value): mixed + public function phpTypecast(mixed $value): StringableStream|string|null { if (is_string($value) && str_starts_with($value, '\x')) { return hex2bin(substr($value, 2)); } - return $value; + return parent::phpTypecast($value); } } diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index f97d43a00..e0c3e0c73 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -75,7 +75,7 @@ protected function assertTypecastedValues(array $result, bool $allTypecasted = f $this->assertSame(1, $result['int_col']); $this->assertSame(str_repeat('x', 100), $result['char_col']); $this->assertSame(1.234, $result['float_col']); - $this->assertSame("\x10\x11\x12", stream_get_contents($result['blob_col'])); + $this->assertSame("\x10\x11\x12", (string) $result['blob_col']); $this->assertEquals(new DateTimeImmutable('2023-07-11 14:50:23', new DateTimeZone('UTC')), $result['timestamp_col']); $this->assertEquals(new DateTimeImmutable('2023-07-11 14:50:23'), $result['timestamp_default']); $this->assertFalse($result['bool_col']); diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 87276b065..d58280bb3 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -507,6 +507,7 @@ public static function prepareValue(): array $values['binary'][0] = "'\\x737472696e67'::bytea"; $values['paramBinary'][0] = "'\\x737472696e67'::bytea"; $values['paramResource'][0] = "'\\x737472696e67'::bytea"; + $values['ResourceStream'][0] = "'\\x737472696e67'::bytea"; $values['array'][0] = "ARRAY['a','b','c']"; $values['Iterator'][0] = "ARRAY['a','b','c']"; From af5cd713c1713e427a1742487cd185be801a7a9c Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 4 Aug 2025 16:37:59 +0000 Subject: [PATCH 2/5] Apply fixes from StyleCI --- tests/ColumnTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/ColumnTest.php b/tests/ColumnTest.php index e0c3e0c73..d625bab6e 100644 --- a/tests/ColumnTest.php +++ b/tests/ColumnTest.php @@ -32,7 +32,6 @@ use function iterator_to_array; use function str_repeat; -use function stream_get_contents; /** * @group pgsql From a0caf6f30ec8baca4caedb7c4b13554c0951c907 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 4 Aug 2025 20:20:52 +0300 Subject: [PATCH 3/5] Fix psalm --- src/Column/BinaryColumn.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Column/BinaryColumn.php b/src/Column/BinaryColumn.php index 306b9628e..046817343 100644 --- a/src/Column/BinaryColumn.php +++ b/src/Column/BinaryColumn.php @@ -17,6 +17,7 @@ final class BinaryColumn extends BaseBinaryColumn public function phpTypecast(mixed $value): StringableStream|string|null { if (is_string($value) && str_starts_with($value, '\x')) { + /** @var string */ return hex2bin(substr($value, 2)); } From e1c32e5d8d86baf374679055f064017be0c8e08c Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 4 Aug 2025 23:08:52 +0300 Subject: [PATCH 4/5] Update CHANGELOG.md [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index af9086ebc..031cd5263 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Chg #416: Use `\InvalidArgumentException` instead of `Yiisoft\Db\Exception\InvalidArgumentException` (@DikoIbragimov) - Enh #336, #405: Implement and use `SqlParser` class (@Tigrov) -- New #315: Implement `ColumnSchemaInterface` classes according to the data type of database table columns +- New #315, #1013: Implement `ColumnInterface` classes according to the data type of database table columns for type casting performance. Related with yiisoft/db#752 (@Tigrov) - Chg #348: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) - Enh #349: Add method chaining for column classes (@Tigrov) From 6191eeb9bf74bed1cd0289344e963da4db47c674 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 4 Aug 2025 23:09:36 +0300 Subject: [PATCH 5/5] Update CHANGELOG.md [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 031cd5263..b8490e25c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ - Chg #416: Use `\InvalidArgumentException` instead of `Yiisoft\Db\Exception\InvalidArgumentException` (@DikoIbragimov) - Enh #336, #405: Implement and use `SqlParser` class (@Tigrov) -- New #315, #1013: Implement `ColumnInterface` classes according to the data type of database table columns +- New #315, #432: Implement `ColumnInterface` classes according to the data type of database table columns for type casting performance. Related with yiisoft/db#752 (@Tigrov) - Chg #348: Replace call of `SchemaInterface::getRawTableName()` to `QuoterInterface::getRawTableName()` (@Tigrov) - Enh #349: Add method chaining for column classes (@Tigrov)