Skip to content

Commit

Permalink
支持将字段设置Binary属性
Browse files Browse the repository at this point in the history
  • Loading branch information
evalor committed Jul 11, 2019
1 parent d4bc67b commit 747da02
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/DDLBuilder/Blueprints/ColumnBlueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ColumnBlueprint
protected $columnComment; // 字段注释
protected $columnCharset; // 字段编码

protected $isBinary; // 二进制 (只允许在字符串类型上设置)
protected $isUnique; // 唯一的 (请勿重复设置索引UNI)
protected $unsigned; // 无符号 (仅数字类型可以设置)
protected $zeroFill; // 零填充 (仅数字类型可以设置)
Expand Down Expand Up @@ -171,6 +172,22 @@ function setIsAutoIncrement(bool $enable = true): ColumnBlueprint
return $this;
}


/**
* 是否二进制
* 在字符列上设置了二进制会使得该列严格区分大小写
* @param bool $enable
* @return ColumnBlueprint
*/
function setIsBinary(bool $enable = true): ColumnBlueprint
{
// TODO 暂未做规范判断
// 同样需要做规范判断 只有字符串类型才允许二进制

$this->isBinary = $enable;
return $this;
}

/**
* 直接在字段上设置PK
* 请不要和索引互相重复设置
Expand Down Expand Up @@ -268,6 +285,7 @@ function __createDDL(): string
[
'`' . $this->columnName . '`',
(string)$this->parseDataType(),
$this->isBinary ? 'BINARY' : null,
$this->columnCharset ? 'CHARACTER SET ' . strtoupper($columnCharset) . ' COLLATE ' . strtoupper($this->columnCharset) : null,
$this->unsigned ? 'UNSIGNED' : null,
$this->zeroFill ? 'ZEROFILL' : null,
Expand Down

0 comments on commit 747da02

Please sign in to comment.