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