- Fixed in the query builder (still a big WIP)
This commit is contained in:
1 parent
efa957fe58
commit
bcbf65e0b3
3 files changed
+16
-10
No files matched your search
@@ -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
|
||||
|
||||
Reference in new issue
Block a user