-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from sartor/master
Column builder
- Loading branch information
Showing
5 changed files
with
401 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
|
||
namespace bashkarev\clickhouse; | ||
|
||
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder; | ||
|
||
/** | ||
* ColumnSchemaBuilder is the schema builder for ClickHouse databases. | ||
* | ||
* @author Sartor <[email protected]> | ||
*/ | ||
class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder | ||
{ | ||
/** | ||
* @var bool whether the column is or not nullable. | ||
* If this is `false`, a `Nullable` type wrapper will be added. | ||
*/ | ||
protected $isNotNull = true; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function defaultValue($default) | ||
{ | ||
$this->default = $default; | ||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function buildNotNullString() | ||
{ | ||
if ($this->isNotNull !== true) { | ||
return ' NULL'; | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function buildUnsignedString() | ||
{ | ||
return $this->isUnsigned ? 'U' : ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function buildAfterString() | ||
{ | ||
return $this->after !== null ? | ||
' AFTER ' . $this->db->quoteColumnName($this->after) : | ||
''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function buildFirstString() | ||
{ | ||
return $this->isFirst ? ' FIRST' : ''; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function buildDefaultString() | ||
{ | ||
$result = parent::buildDefaultString(); | ||
|
||
if ($this->default === null && $this->isNotNull === false) { | ||
return ''; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function __toString() | ||
{ | ||
switch ($this->getTypeCategory()) { | ||
case self::CATEGORY_NUMERIC: | ||
$format = "{unsigned}{type}{notnull}{default}{append}{pos}"; | ||
break; | ||
default: | ||
$format = "{type}{length}{notnull}{default}{check}{append}{pos}"; | ||
} | ||
|
||
return $this->buildCompleteString($format); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.