This commit is contained in:
Roman 2023-01-11 15:28:47 +01:00
parent 4c51403daa
commit 05fd209204
7 changed files with 61 additions and 5 deletions

@ -77,7 +77,12 @@ class Parameter {
public function getTypeName(): string {
$typeName = Parameter::names[$this->type] ?? "INVALID";
if ($this->choices) {
$typeName .= ", choices: " . json_encode($this->choices);
$typeName .= ", choices=" . json_encode($this->choices);
}
$format = $this->getSwaggerFormat();
if ($format && $this->type !== self::TYPE_EMAIL) {
$typeName .= ", format='$format'";
}
return $typeName;

@ -12,7 +12,8 @@ use Core\Objects\DatabaseEntity\User;
trait Pagination {
static function getPaginationParameters(array $orderColumns, string $defaultOrderBy = "id", string $defaultSortOrder = "asc"): array {
function getPaginationParameters(array $orderColumns, string $defaultOrderBy = "id", string $defaultSortOrder = "asc"): array {
$this->paginationOrderColumns = $orderColumns;
return [
'page' => new Parameter('page', Parameter::TYPE_INT, true, 1),
'count' => new Parameter('count', Parameter::TYPE_INT, true, 20),

@ -0,0 +1,25 @@
<?php
namespace Core\Driver\SQL\Expression;
use Core\Driver\SQL\SQL;
class Coalesce extends Expression {
private array $values;
public function __construct(mixed ...$values) {
$this->values = $values;
}
function getExpression(SQL $sql, array &$params): string {
$values = implode(",", array_map(function ($value) use ($sql, &$params) {
if (is_string($value)) {
return $sql->columnName($value);
} else {
return $sql->addValue($value, $params);
}
}, $this->values));
return "COALESCE($values)";
}
}

@ -0,0 +1,22 @@
<?php
namespace Core\Driver\SQL\Expression;
use Core\Driver\SQL\SQL;
class NullIf extends Expression {
private mixed $lhs;
private mixed $rhs;
public function __construct(mixed $lhs, mixed $rhs) {
$this->lhs = $lhs;
$this->rhs = $rhs;
}
function getExpression(SQL $sql, array &$params): string {
$lhs = $sql->addValue($this->lhs, $params);
$rhs = $sql->addValue($this->rhs, $params);
return "NULLIF($lhs, $rhs)";
}
}

@ -109,7 +109,7 @@ abstract class DatabaseEntity implements ArrayAccess, JsonSerializable {
}
}
if ($propertyNames === null) {
if ($propertyNames === null && !empty($this->customData)) {
$jsonArray = array_merge($jsonArray, $this->customData);
}

@ -74,6 +74,9 @@ class DatabaseEntityHandler implements Persistable {
}
public function init() {
$className = $this->entityClass->getName();
$uniqueColumns = self::getAttribute($this->entityClass, Unique::class);
if ($uniqueColumns) {
$this->constraints[] = new \Core\Driver\SQL\Constraint\Unique($uniqueColumns->getColumns());

@ -58,9 +58,9 @@ class NMRelation implements Persistable {
public function getOtherHandler(DatabaseEntityHandler $handler): DatabaseEntityHandler {
if ($handler === $this->thisHandler) {
return $this->thisHandler;
} else {
return $this->otherHandler;
} else {
return $this->thisHandler;
}
}
}