Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision

Target

Select target project
  • grifart/tables
1 result
Select Git revision
Show changes
Commits on Source (3)
......@@ -95,11 +95,11 @@ To retrieve a list of records that match given criteria, you can use the `findBy
$rows = $table->findBy($conditions, $orderBy, $paginator);
```
There are also two pairs of helper methods to retrieve a *single* record that matches given criteria: `getOneBy()` and `findOneBy()` look for a unique record and throw an exception when the query yields more than one result. In addition, `getOneBy()` fails if no record is found, whereas `findOneBy()` returns null in such case.
There are also two pairs of helper methods to retrieve a *single* record that matches given criteria: `getUniqueBy()` and `findUniqueBy()` look for a unique record and throw an exception when the query yields more than one result. In addition, `getUniqueBy()` fails if no record is found, whereas `findUniqueBy()` returns null in such case.
```php
$row = $table->getOneBy($conditions);
$rowOrNull = $table->findOneBy($conditions);
$row = $table->getUniqueBy($conditions);
$rowOrNull = $table->findUniqueBy($conditions);
```
And `getFirstBy()` and `findFirstBy()` return the first record that matches given criteria, regardless of whether there are more of them in the table.
......
......@@ -89,9 +89,6 @@ final class TableImplementation implements Capability
->setBody("return [\n".$columnsArrayTemplate."\n];", $columnsDefinitions);
// Column references
// todo add - use constants? Or references to Column class?
$classType->addMethod('find')
->setParameters([
(new Code\Parameter('primaryKey'))
......@@ -99,12 +96,9 @@ final class TableImplementation implements Capability
])
->setReturnType($this->rowClass)
->setReturnNullable()
->setBody(
'$row = $this->tableManager->find($this, $primaryKey);' . "\n" .
'\assert($row instanceof ? || $row === NULL);' . "\n" .
'return $row;',
[new Code\Literal($namespace->simplifyName($this->rowClass))]
);
->addBody('$row = $this->tableManager->find($this, $primaryKey, required: false);')
->addBody('\assert($row instanceof ? || $row === null);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('return $row;');
$namespace->addUse(RowNotFound::class);
$classType->addMethod('get')
......@@ -114,13 +108,9 @@ final class TableImplementation implements Capability
])
->setReturnType($this->rowClass)
->addComment('@throws RowNotFound')
->setBody(
'$row = $this->find($primaryKey);' . "\n" .
'if ($row === NULL) {' . "\n" .
' throw new RowNotFound();' . "\n" .
'}' . "\n" .
'return $row;'
);
->addBody('$row = $this->tableManager->find($this, $primaryKey, required: true);')
->addBody('\assert($row instanceof ?);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('return $row;');
$namespace->addUse(OrderBy::class);
$namespace->addUse(Paginator::class);
......@@ -158,7 +148,7 @@ final class TableImplementation implements Capability
$namespace->addUse(TooManyRowsFound::class);
$classType->addMethod('getOneBy')
$classType->addMethod('getUniqueBy')
->setParameters([
(new Code\Parameter('conditions'))->setType(Condition::class . '|array'),
])
......@@ -166,24 +156,21 @@ final class TableImplementation implements Capability
->addComment('@return ' . $namespace->simplifyName($this->rowClass))
->addComment('@throws RowNotFound')
->setReturnType($this->rowClass)
->addBody('[$row, $count] = $this->tableManager->findOneBy($this, $conditions);')
->addBody('\assert($row instanceof ? || $row === null);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('if ($row === null) { throw new RowNotFound(); }')
->addBody('if ($count > 1) { throw new TooManyRowsFound(); }')
->addBody('$row = $this->tableManager->findOneBy($this, $conditions, required: true, unique: true);')
->addBody('\assert($row instanceof ?);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('return $row;');
$classType->addMethod('findOneBy')
$classType->addMethod('findUniqueBy')
->setParameters([
(new Code\Parameter('conditions'))->setType(Condition::class . '|array'),
])
->addComment('@param Condition|Condition[] $conditions')
->addComment('@return ' . $namespace->simplifyName($this->rowClass))
->addComment('@return ' . $namespace->simplifyName($this->rowClass) . '|null')
->addComment('@throws RowNotFound')
->setReturnType($this->rowClass)
->setReturnNullable()
->addBody('[$row, $count] = $this->tableManager->findOneBy($this, $conditions);')
->addBody('$row = $this->tableManager->findOneBy($this, $conditions, required: false, unique: true);')
->addBody('\assert($row instanceof ? || $row === null);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('if ($count > 1) { throw new TooManyRowsFound(); }')
->addBody('return $row;');
$classType->addMethod('getFirstBy')
......@@ -196,9 +183,8 @@ final class TableImplementation implements Capability
->addComment('@return ' . $namespace->simplifyName($this->rowClass))
->addComment('@throws RowNotFound')
->setReturnType($this->rowClass)
->addBody('[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);')
->addBody('\assert($row instanceof ? || $row === null);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('if ($row === null) { throw new RowNotFound(); }')
->addBody('$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: true, unique: false);')
->addBody('\assert($row instanceof ?);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('return $row;');
$classType->addMethod('findFirstBy')
......@@ -208,11 +194,10 @@ final class TableImplementation implements Capability
])
->addComment('@param Condition|Condition[] $conditions')
->addComment('@param array<OrderBy|Expression<mixed>> $orderBy')
->addComment('@return ' . $namespace->simplifyName($this->rowClass))
->addComment('@throws RowNotFound')
->addComment('@return ' . $namespace->simplifyName($this->rowClass) . '|null')
->setReturnType($this->rowClass)
->setReturnNullable()
->addBody('[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);')
->addBody('$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: false, unique: false);')
->addBody('\assert($row instanceof ? || $row === null);', [new Code\Literal($namespace->simplifyName($this->rowClass))])
->addBody('return $row;');
......@@ -224,9 +209,9 @@ final class TableImplementation implements Capability
->addComment('@param Condition|Condition[] $conditions')
->addComment('@return ' . $namespace->simplifyName($this->rowClass))
->addComment('@throws RowNotFound')
->addAttribute(\Deprecated::class, ['Use getOneBy() instead.'])
->addAttribute(\Deprecated::class, ['Use getUniqueBy() instead.'])
->setReturnType($this->rowClass)
->addBody('return $this->getOneBy($conditions);');
->addBody('return $this->getUniqueBy($conditions);');
$newMethod = $classType->addMethod('new')
......
......@@ -54,17 +54,12 @@ final class TableManager
* @template TableType of Table
* @param TableType $table
* @param PrimaryKey<TableType> $primaryKey
* @return null|Row
* @return ($required is true ? Row : Row|null)
* @throws RowNotFound
*/
public function find(Table $table, PrimaryKey $primaryKey): ?Row
public function find(Table $table, PrimaryKey $primaryKey, bool $required = true): ?Row
{
$rows = $this->findBy($table, $primaryKey->getCondition($table));
if (\count($rows) === 1) {
$row = \reset($rows);
return $row;
}
\assert(\count($rows) === 0);
return NULL;
return $this->findOneBy($table, $primaryKey->getCondition($table), required: $required);
}
/**
......@@ -142,9 +137,10 @@ final class TableManager
* @param TableType $table
* @param Condition|Condition[] $conditions
* @param array<OrderBy|Expression<mixed>> $orderBy
* @return array{Row|null, int}
* @return ($required is true ? Row : Row|null)
* @throws RowNotFound
*/
public function findOneBy(Table $table, Condition|array $conditions, array $orderBy = [], bool $checkCount = true): array
public function findOneBy(Table $table, Condition|array $conditions, array $orderBy = [], bool $required = true, bool $unique = true): ?Row
{
$result = $this->connection->query(
'SELECT *',
......@@ -159,32 +155,30 @@ final class TableManager
return $orderBy->toSql()->getValues();
})
: [['%sql', 'true::boolean']],
'%lmt', $checkCount ? 2 : 1,
);
foreach ($table::getDatabaseColumns() as $column) {
$result->setType($column->getName(), NULL);
}
$dibiRows = $result->fetchAll();
$dibiRow = $result->fetch();
if ($dibiRow === null) {
return ! $required ? null : throw new RowNotFound();
}
/** @var class-string<Row> $rowClass */
$rowClass = $table::getRowClass();
$modelRows = [];
foreach ($dibiRows as $dibiRow) {
\assert($dibiRow instanceof \Dibi\Row);
$modelRows[] = $rowClass::reconstitute(
mapWithKeys(
$dibiRow->toArray(),
static fn(string $columnName, mixed $value) => $value !== null ? $table->getTypeOf($columnName)->fromDatabase($value) : null,
),
);
if ($unique && $result->fetch() !== null) {
throw new TooManyRowsFound();
}
return [
$modelRows[0] ?? null,
\count($modelRows),
];
/** @var class-string<Row> $rowClass */
$rowClass = $table::getRowClass();
\assert($dibiRow instanceof \Dibi\Row);
return $rowClass::reconstitute(
mapWithKeys(
$dibiRow->toArray(),
static fn(string $columnName, mixed $value) => $value !== null ? $table->getTypeOf($columnName)->fromDatabase($value) : null,
),
);
}
/**
......
......@@ -22,17 +22,17 @@ $table = new ConfigTable(
TestFixtures::createTypeResolver($connection),
);
$row = $table->getOneBy($table->key()->is('key1'));
$row = $table->getUniqueBy($table->key()->is('key1'));
Assert::same('same value', $row->getValue());
Assert::throws(fn() => $table->getOneBy($table->key()->is('key4')), RowNotFound::class);
Assert::throws(fn() => $table->getOneBy($table->value()->is('same value')), TooManyRowsFound::class);
Assert::throws(fn() => $table->getUniqueBy($table->key()->is('key4')), RowNotFound::class);
Assert::throws(fn() => $table->getUniqueBy($table->value()->is('same value')), TooManyRowsFound::class);
$row = $table->findOneBy($table->key()->is('key1'));
$row = $table->findUniqueBy($table->key()->is('key1'));
Assert::same('same value', $row->getValue());
Assert::null($table->findOneBy($table->key()->is('key4')));
Assert::throws(fn() => $table->findOneBy($table->value()->is('same value')), TooManyRowsFound::class);
Assert::null($table->findUniqueBy($table->key()->is('key4')));
Assert::throws(fn() => $table->findUniqueBy($table->value()->is('same value')), TooManyRowsFound::class);
$row = $table->getFirstBy($table->key()->is('key1'));
Assert::same('same value', $row->getValue());
......
......@@ -80,8 +80,8 @@ final class ConfigTable implements Table
public function find(ConfigPrimaryKey $primaryKey): ?ConfigRow
{
$row = $this->tableManager->find($this, $primaryKey);
\assert($row instanceof ConfigRow || $row === NULL);
$row = $this->tableManager->find($this, $primaryKey, required: false);
\assert($row instanceof ConfigRow || $row === null);
return $row;
}
......@@ -91,10 +91,8 @@ final class ConfigTable implements Table
*/
public function get(ConfigPrimaryKey $primaryKey): ConfigRow
{
$row = $this->find($primaryKey);
if ($row === NULL) {
throw new RowNotFound();
}
$row = $this->tableManager->find($this, $primaryKey, required: true);
\assert($row instanceof ConfigRow);
return $row;
}
......@@ -129,26 +127,23 @@ final class ConfigTable implements Table
* @return ConfigRow
* @throws RowNotFound
*/
public function getOneBy(Condition|array $conditions): ConfigRow
public function getUniqueBy(Condition|array $conditions): ConfigRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
\assert($row instanceof ConfigRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
if ($count > 1) { throw new TooManyRowsFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, required: true, unique: true);
\assert($row instanceof ConfigRow);
return $row;
}
/**
* @param Condition|Condition[] $conditions
* @return ConfigRow
* @return ConfigRow|null
* @throws RowNotFound
*/
public function findOneBy(Condition|array $conditions): ?ConfigRow
public function findUniqueBy(Condition|array $conditions): ?ConfigRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
$row = $this->tableManager->findOneBy($this, $conditions, required: false, unique: true);
\assert($row instanceof ConfigRow || $row === null);
if ($count > 1) { throw new TooManyRowsFound(); }
return $row;
}
......@@ -161,9 +156,8 @@ final class ConfigTable implements Table
*/
public function getFirstBy(Condition|array $conditions, array $orderBy = []): ConfigRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
\assert($row instanceof ConfigRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: true, unique: false);
\assert($row instanceof ConfigRow);
return $row;
}
......@@ -171,12 +165,11 @@ final class ConfigTable implements Table
/**
* @param Condition|Condition[] $conditions
* @param array<OrderBy|Expression<mixed>> $orderBy
* @return ConfigRow
* @throws RowNotFound
* @return ConfigRow|null
*/
public function findFirstBy(Condition|array $conditions, array $orderBy = []): ?ConfigRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: false, unique: false);
\assert($row instanceof ConfigRow || $row === null);
return $row;
}
......@@ -187,10 +180,10 @@ final class ConfigTable implements Table
* @return ConfigRow
* @throws RowNotFound
*/
#[\Deprecated('Use getOneBy() instead.')]
#[\Deprecated('Use getUniqueBy() instead.')]
public function getBy(Condition|array $conditions): ConfigRow
{
return $this->getOneBy($conditions);
return $this->getUniqueBy($conditions);
}
......
......@@ -80,8 +80,8 @@ final class GeneratedTable implements Table
public function find(GeneratedPrimaryKey $primaryKey): ?GeneratedRow
{
$row = $this->tableManager->find($this, $primaryKey);
\assert($row instanceof GeneratedRow || $row === NULL);
$row = $this->tableManager->find($this, $primaryKey, required: false);
\assert($row instanceof GeneratedRow || $row === null);
return $row;
}
......@@ -91,10 +91,8 @@ final class GeneratedTable implements Table
*/
public function get(GeneratedPrimaryKey $primaryKey): GeneratedRow
{
$row = $this->find($primaryKey);
if ($row === NULL) {
throw new RowNotFound();
}
$row = $this->tableManager->find($this, $primaryKey, required: true);
\assert($row instanceof GeneratedRow);
return $row;
}
......@@ -129,26 +127,23 @@ final class GeneratedTable implements Table
* @return GeneratedRow
* @throws RowNotFound
*/
public function getOneBy(Condition|array $conditions): GeneratedRow
public function getUniqueBy(Condition|array $conditions): GeneratedRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
\assert($row instanceof GeneratedRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
if ($count > 1) { throw new TooManyRowsFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, required: true, unique: true);
\assert($row instanceof GeneratedRow);
return $row;
}
/**
* @param Condition|Condition[] $conditions
* @return GeneratedRow
* @return GeneratedRow|null
* @throws RowNotFound
*/
public function findOneBy(Condition|array $conditions): ?GeneratedRow
public function findUniqueBy(Condition|array $conditions): ?GeneratedRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
$row = $this->tableManager->findOneBy($this, $conditions, required: false, unique: true);
\assert($row instanceof GeneratedRow || $row === null);
if ($count > 1) { throw new TooManyRowsFound(); }
return $row;
}
......@@ -161,9 +156,8 @@ final class GeneratedTable implements Table
*/
public function getFirstBy(Condition|array $conditions, array $orderBy = []): GeneratedRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
\assert($row instanceof GeneratedRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: true, unique: false);
\assert($row instanceof GeneratedRow);
return $row;
}
......@@ -171,12 +165,11 @@ final class GeneratedTable implements Table
/**
* @param Condition|Condition[] $conditions
* @param array<OrderBy|Expression<mixed>> $orderBy
* @return GeneratedRow
* @throws RowNotFound
* @return GeneratedRow|null
*/
public function findFirstBy(Condition|array $conditions, array $orderBy = []): ?GeneratedRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: false, unique: false);
\assert($row instanceof GeneratedRow || $row === null);
return $row;
}
......@@ -187,10 +180,10 @@ final class GeneratedTable implements Table
* @return GeneratedRow
* @throws RowNotFound
*/
#[\Deprecated('Use getOneBy() instead.')]
#[\Deprecated('Use getUniqueBy() instead.')]
public function getBy(Condition|array $conditions): GeneratedRow
{
return $this->getOneBy($conditions);
return $this->getUniqueBy($conditions);
}
......
......@@ -80,8 +80,8 @@ final class PackagesTable implements Table
public function find(PackagePrimaryKey $primaryKey): ?PackageRow
{
$row = $this->tableManager->find($this, $primaryKey);
\assert($row instanceof PackageRow || $row === NULL);
$row = $this->tableManager->find($this, $primaryKey, required: false);
\assert($row instanceof PackageRow || $row === null);
return $row;
}
......@@ -91,10 +91,8 @@ final class PackagesTable implements Table
*/
public function get(PackagePrimaryKey $primaryKey): PackageRow
{
$row = $this->find($primaryKey);
if ($row === NULL) {
throw new RowNotFound();
}
$row = $this->tableManager->find($this, $primaryKey, required: true);
\assert($row instanceof PackageRow);
return $row;
}
......@@ -129,26 +127,23 @@ final class PackagesTable implements Table
* @return PackageRow
* @throws RowNotFound
*/
public function getOneBy(Condition|array $conditions): PackageRow
public function getUniqueBy(Condition|array $conditions): PackageRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
\assert($row instanceof PackageRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
if ($count > 1) { throw new TooManyRowsFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, required: true, unique: true);
\assert($row instanceof PackageRow);
return $row;
}
/**
* @param Condition|Condition[] $conditions
* @return PackageRow
* @return PackageRow|null
* @throws RowNotFound
*/
public function findOneBy(Condition|array $conditions): ?PackageRow
public function findUniqueBy(Condition|array $conditions): ?PackageRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
$row = $this->tableManager->findOneBy($this, $conditions, required: false, unique: true);
\assert($row instanceof PackageRow || $row === null);
if ($count > 1) { throw new TooManyRowsFound(); }
return $row;
}
......@@ -161,9 +156,8 @@ final class PackagesTable implements Table
*/
public function getFirstBy(Condition|array $conditions, array $orderBy = []): PackageRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
\assert($row instanceof PackageRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: true, unique: false);
\assert($row instanceof PackageRow);
return $row;
}
......@@ -171,12 +165,11 @@ final class PackagesTable implements Table
/**
* @param Condition|Condition[] $conditions
* @param array<OrderBy|Expression<mixed>> $orderBy
* @return PackageRow
* @throws RowNotFound
* @return PackageRow|null
*/
public function findFirstBy(Condition|array $conditions, array $orderBy = []): ?PackageRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: false, unique: false);
\assert($row instanceof PackageRow || $row === null);
return $row;
}
......@@ -187,10 +180,10 @@ final class PackagesTable implements Table
* @return PackageRow
* @throws RowNotFound
*/
#[\Deprecated('Use getOneBy() instead.')]
#[\Deprecated('Use getUniqueBy() instead.')]
public function getBy(Condition|array $conditions): PackageRow
{
return $this->getOneBy($conditions);
return $this->getUniqueBy($conditions);
}
......
......@@ -80,8 +80,8 @@ final class TestsTable implements Table
public function find(TestPrimaryKey $primaryKey): ?TestRow
{
$row = $this->tableManager->find($this, $primaryKey);
\assert($row instanceof TestRow || $row === NULL);
$row = $this->tableManager->find($this, $primaryKey, required: false);
\assert($row instanceof TestRow || $row === null);
return $row;
}
......@@ -91,10 +91,8 @@ final class TestsTable implements Table
*/
public function get(TestPrimaryKey $primaryKey): TestRow
{
$row = $this->find($primaryKey);
if ($row === NULL) {
throw new RowNotFound();
}
$row = $this->tableManager->find($this, $primaryKey, required: true);
\assert($row instanceof TestRow);
return $row;
}
......@@ -129,26 +127,23 @@ final class TestsTable implements Table
* @return TestRow
* @throws RowNotFound
*/
public function getOneBy(Condition|array $conditions): TestRow
public function getUniqueBy(Condition|array $conditions): TestRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
\assert($row instanceof TestRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
if ($count > 1) { throw new TooManyRowsFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, required: true, unique: true);
\assert($row instanceof TestRow);
return $row;
}
/**
* @param Condition|Condition[] $conditions
* @return TestRow
* @return TestRow|null
* @throws RowNotFound
*/
public function findOneBy(Condition|array $conditions): ?TestRow
public function findUniqueBy(Condition|array $conditions): ?TestRow
{
[$row, $count] = $this->tableManager->findOneBy($this, $conditions);
$row = $this->tableManager->findOneBy($this, $conditions, required: false, unique: true);
\assert($row instanceof TestRow || $row === null);
if ($count > 1) { throw new TooManyRowsFound(); }
return $row;
}
......@@ -161,9 +156,8 @@ final class TestsTable implements Table
*/
public function getFirstBy(Condition|array $conditions, array $orderBy = []): TestRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
\assert($row instanceof TestRow || $row === null);
if ($row === null) { throw new RowNotFound(); }
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: true, unique: false);
\assert($row instanceof TestRow);
return $row;
}
......@@ -171,12 +165,11 @@ final class TestsTable implements Table
/**
* @param Condition|Condition[] $conditions
* @param array<OrderBy|Expression<mixed>> $orderBy
* @return TestRow
* @throws RowNotFound
* @return TestRow|null
*/
public function findFirstBy(Condition|array $conditions, array $orderBy = []): ?TestRow
{
[$row] = $this->tableManager->findOneBy($this, $conditions, $orderBy, checkCount: false);
$row = $this->tableManager->findOneBy($this, $conditions, $orderBy, required: false, unique: false);
\assert($row instanceof TestRow || $row === null);
return $row;
}
......@@ -187,10 +180,10 @@ final class TestsTable implements Table
* @return TestRow
* @throws RowNotFound
*/
#[\Deprecated('Use getOneBy() instead.')]
#[\Deprecated('Use getUniqueBy() instead.')]
public function getBy(Condition|array $conditions): TestRow
{
return $this->getOneBy($conditions);
return $this->getUniqueBy($conditions);
}
......
......@@ -112,7 +112,7 @@ $nullDetails = $table->findBy($table->details()->is(null));
Assert::count(1, $nullDetails);
Assert::same(0, $nullDetails[0]->getScore());
$unique = $table->getOneBy($table->score()->is(42));
$unique = $table->getUniqueBy($table->score()->is(42));
Assert::same(42, $unique->getScore());
$table->update($table->edit(
......