- Fixed in the query builder (still a big WIP)
This commit is contained in:
parent
efa957fe58
commit
bcbf65e0b3
|
@ -16,7 +16,7 @@ class Field implements \Ulmus\Annotation\Annotation {
|
||||||
|
|
||||||
public array $attributes = [];
|
public array $attributes = [];
|
||||||
|
|
||||||
public bool $nullable = false;
|
public bool $nullable;
|
||||||
|
|
||||||
public function __construct(? string $type = null, ? int $length = null)
|
public function __construct(? string $type = null, ? int $length = null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,7 +58,7 @@ class EntityField
|
||||||
return implode(" ", [
|
return implode(" ", [
|
||||||
$definition->getSqlName(),
|
$definition->getSqlName(),
|
||||||
$definition->getSqlType(),
|
$definition->getSqlType(),
|
||||||
|
$definition->getSqlParams(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,11 +28,12 @@ class FieldDefinition {
|
||||||
$this->builtIn = $data['builtin'];
|
$this->builtIn = $data['builtin'];
|
||||||
$this->tags = $data['tags'];
|
$this->tags = $data['tags'];
|
||||||
|
|
||||||
|
|
||||||
$field = $this->getFieldTag();
|
$field = $this->getFieldTag();
|
||||||
$this->type = $field->type ?? $data['type'];
|
$this->type = $field->type ?? $data['type'];
|
||||||
$this->length = $field->length ?? null;
|
$this->length = $field->length ?? null;
|
||||||
$this->precision = $field->precision ?? null;
|
$this->precision = $field->precision ?? null;
|
||||||
$this->nullable = $field->nullable ?? $data['nullable'];
|
$this->nullable = isset($field->nullable) ? $field->nullable : $data['nullable'];
|
||||||
$this->update = $field->attributes['update'] ?? null;
|
$this->update = $field->attributes['update'] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +42,10 @@ class FieldDefinition {
|
||||||
return $this->getColumnName();
|
return $this->getColumnName();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getSqlType() : string
|
public function getSqlType(bool $typeOnly = false) : string
|
||||||
{
|
{
|
||||||
$type = $this->type;
|
$type = $this->type;
|
||||||
$length = $this->length;
|
$length = $this->length;
|
||||||
$default = $this->getDefault();
|
|
||||||
|
|
||||||
switch($type) {
|
switch($type) {
|
||||||
case "bool":
|
case "bool":
|
||||||
|
@ -86,8 +86,14 @@ class FieldDefinition {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $typeOnly ? $type : $type . ( $length ? "($length" . ( $precision ? ",$precision" : "" ) . ")" : "" );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSqlParams() : string
|
||||||
|
{
|
||||||
|
$default = $this->getDefault();
|
||||||
|
|
||||||
return implode(' ', array_filter([
|
return implode(' ', array_filter([
|
||||||
$type . ( $length ? "($length" . ( $precision ? ",$precision" : "" ) . ")" : "" ),
|
|
||||||
$this->isUnsigned() ? "UNSIGNED" : null,
|
$this->isUnsigned() ? "UNSIGNED" : null,
|
||||||
$this->nullable ? "NULL" : "NOT NULL",
|
$this->nullable ? "NULL" : "NOT NULL",
|
||||||
$default ? "DEFAULT $default" : null,
|
$default ? "DEFAULT $default" : null,
|
||||||
|
@ -112,7 +118,7 @@ class FieldDefinition {
|
||||||
|
|
||||||
protected function getDefault() : ? string
|
protected function getDefault() : ? string
|
||||||
{
|
{
|
||||||
return $this->getFieldTag()->attributes['default'] ?? null;
|
return $this->getFieldTag()->attributes['default'] ?? ( $this->nullable ? "NULL" : null ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function isPrimaryKey() : bool
|
protected function isPrimaryKey() : bool
|
||||||
|
|
Loading…
Reference in New Issue