Skip to content

Commit

Permalink
字段支持单独设置字符集
Browse files Browse the repository at this point in the history
  • Loading branch information
evalor committed Jul 11, 2019
1 parent 69d36da commit d4bc67b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/DDLBuilder/Blueprints/ColumnBlueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ColumnBlueprint
protected $columnType; // 字段类型
protected $columnLimit; // 字段限制 如 INT(11) / decimal(10,2) 括号部分
protected $columnComment; // 字段注释
protected $columnCharset; // 字段编码

protected $isUnique; // 唯一的 (请勿重复设置索引UNI)
protected $unsigned; // 无符号 (仅数字类型可以设置)
Expand Down Expand Up @@ -94,6 +95,17 @@ function setColumnComment(string $comment): ColumnBlueprint
return $this;
}

/**
* 设置字段编码
* @param string $charset
* @return ColumnBlueprint
*/
function setColumnCharset(string $charset): ColumnBlueprint
{
$this->columnCharset = $charset;
return $this;
}


/**
* 是否零填充
Expand Down Expand Up @@ -250,11 +262,13 @@ private function parseDataType()
function __createDDL(): string
{
$default = $this->parseDefaultValue();
$columnCharset = $this->columnCharset ? explode('_', $this->columnCharset)[0] : false;
return implode(' ',
array_filter(
[
'`' . $this->columnName . '`',
(string)$this->parseDataType(),
$this->columnCharset ? 'CHARACTER SET ' . strtoupper($columnCharset) . ' COLLATE ' . strtoupper($this->columnCharset) : null,
$this->unsigned ? 'UNSIGNED' : null,
$this->zeroFill ? 'ZEROFILL' : null,
$this->isUnique ? 'UNIQUE' : null,
Expand Down

0 comments on commit d4bc67b

Please sign in to comment.