|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Schema\Column; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Schema\SchemaInterface; |
|
8
|
|
|
|
|
9
|
|
|
class ColumnBuilder implements ColumnBuilderInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public static function pk(bool $autoIncrement = true): ColumnInterface |
|
12
|
|
|
{ |
|
13
|
|
|
return (new IntegerColumn()) |
|
14
|
|
|
->primaryKey() |
|
15
|
|
|
->autoIncrement($autoIncrement); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public static function upk(bool $autoIncrement = true): ColumnInterface |
|
19
|
|
|
{ |
|
20
|
|
|
return (new ColumnFactory()) |
|
21
|
|
|
->fromType(SchemaInterface::TYPE_INTEGER, ['unsigned' => true]) |
|
22
|
|
|
->primaryKey() |
|
23
|
|
|
->autoIncrement($autoIncrement); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public static function bigpk(bool $autoIncrement = true): ColumnInterface |
|
27
|
|
|
{ |
|
28
|
|
|
return (new ColumnFactory()) |
|
29
|
|
|
->fromType(SchemaInterface::TYPE_BIGINT) |
|
30
|
|
|
->primaryKey() |
|
31
|
|
|
->autoIncrement($autoIncrement); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public static function ubigpk(bool $autoIncrement = true): ColumnInterface |
|
35
|
|
|
{ |
|
36
|
|
|
return (new ColumnFactory()) |
|
37
|
|
|
->fromType(SchemaInterface::TYPE_BIGINT, ['unsigned' => true]) |
|
38
|
|
|
->primaryKey() |
|
39
|
|
|
->autoIncrement($autoIncrement); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public static function uuidpk(bool $autoIncrement = false): ColumnInterface |
|
43
|
|
|
{ |
|
44
|
|
|
return (new ColumnFactory()) |
|
45
|
|
|
->fromType(SchemaInterface::TYPE_UUID) |
|
46
|
|
|
->primaryKey() |
|
47
|
|
|
->autoIncrement($autoIncrement); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public static function uuidpkseq(): ColumnInterface |
|
51
|
|
|
{ |
|
52
|
|
|
return static::uuidpk(true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public static function string(int|null $size = 255): ColumnInterface |
|
56
|
|
|
{ |
|
57
|
|
|
return (new ColumnFactory()) |
|
58
|
|
|
->fromType(SchemaInterface::TYPE_STRING) |
|
59
|
|
|
->size($size); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public static function integer(int|null $size = null): ColumnInterface |
|
63
|
|
|
{ |
|
64
|
|
|
return (new ColumnFactory()) |
|
65
|
|
|
->fromType(SchemaInterface::TYPE_INTEGER) |
|
66
|
|
|
->size($size); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public static function float(int|null $size = null, int|null $scale = null): ColumnInterface |
|
70
|
|
|
{ |
|
71
|
|
|
return (new ColumnFactory()) |
|
72
|
|
|
->fromType(SchemaInterface::TYPE_FLOAT) |
|
73
|
|
|
->size($size) |
|
74
|
|
|
->scale($scale); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public static function double(int|null $size = null, int|null $scale = null): ColumnInterface |
|
78
|
|
|
{ |
|
79
|
|
|
return (new ColumnFactory()) |
|
80
|
|
|
->fromType(SchemaInterface::TYPE_DOUBLE) |
|
81
|
|
|
->size($size) |
|
82
|
|
|
->scale($scale); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
public static function decimal(int|null $size = null, int|null $scale = null): ColumnInterface |
|
86
|
|
|
{ |
|
87
|
|
|
return (new ColumnFactory()) |
|
88
|
|
|
->fromType(SchemaInterface::TYPE_DECIMAL) |
|
89
|
|
|
->size($size) |
|
90
|
|
|
->scale($scale); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public static function money(int|null $size = null, int|null $scale = null): ColumnInterface |
|
94
|
|
|
{ |
|
95
|
|
|
return (new ColumnFactory()) |
|
96
|
|
|
->fromType(SchemaInterface::TYPE_MONEY) |
|
97
|
|
|
->size($size) |
|
98
|
|
|
->scale($scale); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
// ... |
|
102
|
|
|
} |
|
103
|
|
|
|