CompositeType fails with "input of anonymous composite types is not implemented"
When I try to implement composite type, it fails with:
input of anonymous composite types is not implemented
LINE 1: ...128-ba9d-934e6982b02a') AND ("majorVersionNumber" = '(2,0)')
^
LOCATION: record_in, rowtypes.c:103 (Dibi\DriverException)
The problem is that the tuple is quoted with '
– it shouldn't be there. Same problem occurred in previous version of grifart/tables, where I had to workaround it with one of:
'majorVersionNumber%sql' => '(2,3)'
'majorVersionNumber%sql' => 'ROW (2,3)'
This isn't possible now. Actually, it might be possibly implemented with some tuple()
condition passed to findBy()
, but that doesn't apply for direct get()
or inserts/updates. E.g. for insert, there isn't currently possible to pass any dibi modifier.
Current implementation of campaign version type:
/**
* @extends CompositeType<PublishedVersionNumber>
*/
final class CampaignVersionType extends CompositeType
{
public function __construct()
{
parent::__construct(new IntType(), new IntType());
}
public function getPhpType(): PhpType
{
return resolve(PublishedVersionNumber::class);
}
public function getDatabaseTypes(): array
{
return [];
}
public function toDatabase(mixed $value): string
{
return $this->tupleToDatabase([
$value->getMajorVersionNumber(),
$value->getPatchVersionNumber(),
]);
}
public function fromDatabase(mixed $value): PublishedVersionNumber
{
[$major, $patch] = $this->tupleFromDatabase($value);
return PublishedVersionNumber::of($major, $patch);
}
}
MR with failing tests, run e.g. Statistics.read.phpt
to reproduce the issue (or anything which works with publishedCampaigns
table).
Edited by Daniel Kurowski