-
Notifications
You must be signed in to change notification settings - Fork 15
/
ColumnSchemaBuilder.php
96 lines (82 loc) · 1.96 KB
/
ColumnSchemaBuilder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
namespace bashkarev\clickhouse;
use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder;
/**
* ColumnSchemaBuilder is the schema builder for ClickHouse databases.
*
* @author Sartor <sartorua@gmail.com>
*/
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}{length}{notnull}{default}{append}{pos}";
break;
default:
$format = "{type}{length}{notnull}{default}{check}{append}{pos}";
}
return $this->buildCompleteString($format);
}
}