1 | <?php
|
---|
2 |
|
---|
3 | class ModelDesc
|
---|
4 | {
|
---|
5 | public string $Name;
|
---|
6 | public array $Columns;
|
---|
7 | public array $Indices;
|
---|
8 | public string $PrimaryKey;
|
---|
9 | public bool $Memory;
|
---|
10 |
|
---|
11 | function __construct(string $Name)
|
---|
12 | {
|
---|
13 | $this->Name = $Name;
|
---|
14 | $this->Columns = array();
|
---|
15 | $this->Indices = array();
|
---|
16 | $this->PrimaryKey = 'Id';
|
---|
17 | $this->Memory = false;
|
---|
18 | $this->DefaultValuesMethod = null;
|
---|
19 | }
|
---|
20 |
|
---|
21 | function AddString(string $Name): ModelColumnString
|
---|
22 | {
|
---|
23 | $Result = new ModelColumnString($Name);
|
---|
24 | $this->Columns[] = $Result;
|
---|
25 | return $Result;
|
---|
26 | }
|
---|
27 |
|
---|
28 | function AddFloat(string $Name): ModelColumnFloat
|
---|
29 | {
|
---|
30 | $Result = new ModelColumnFloat($Name);
|
---|
31 | $this->Columns[] = $Result;
|
---|
32 | return $Result;
|
---|
33 | }
|
---|
34 |
|
---|
35 | function AddText(string $Name): ModelColumnText
|
---|
36 | {
|
---|
37 | $Result = new ModelColumnText($Name);
|
---|
38 | $this->Columns[] = $Result;
|
---|
39 | return $Result;
|
---|
40 | }
|
---|
41 |
|
---|
42 | function AddInteger(string $Name): ModelColumnInteger
|
---|
43 | {
|
---|
44 | $Result = new ModelColumnInteger($Name);
|
---|
45 | $this->Columns[] = $Result;
|
---|
46 | return $Result;
|
---|
47 | }
|
---|
48 |
|
---|
49 | function AddBigInt(string $Name): ModelColumnBigInt
|
---|
50 | {
|
---|
51 | $Result = new ModelColumnBigInt($Name);
|
---|
52 | $this->Columns[] = $Result;
|
---|
53 | return $Result;
|
---|
54 | }
|
---|
55 |
|
---|
56 | function AddDateTime(string $Name): ModelColumnDateTime
|
---|
57 | {
|
---|
58 | $Result = new ModelColumnDateTime($Name);
|
---|
59 | $this->Columns[] = $Result;
|
---|
60 | return $Result;
|
---|
61 | }
|
---|
62 |
|
---|
63 | function AddDate(string $Name): ModelColumnDate
|
---|
64 | {
|
---|
65 | $Result = new ModelColumnDate($Name);
|
---|
66 | $this->Columns[] = $Result;
|
---|
67 | return $Result;
|
---|
68 | }
|
---|
69 |
|
---|
70 | function AddBoolean(string $Name): ModelColumnBoolean
|
---|
71 | {
|
---|
72 | $Result = new ModelColumnBoolean($Name);
|
---|
73 | $this->Columns[] = $Result;
|
---|
74 | return $Result;
|
---|
75 | }
|
---|
76 |
|
---|
77 | function AddReference(string $Name, string $RefTable, bool $Nullable = true): ModelColumnReference
|
---|
78 | {
|
---|
79 | $Result = new ModelColumnReference($Name, $RefTable);
|
---|
80 | $this->Columns[] = $Result;
|
---|
81 | $Result->Nullable = $Nullable;
|
---|
82 | return $Result;
|
---|
83 | }
|
---|
84 |
|
---|
85 | function AddEnum(string $Name, array $States): ModelColumnEnum
|
---|
86 | {
|
---|
87 | $Result = new ModelColumnEnum($Name, $States);
|
---|
88 | $this->Columns[] = $Result;
|
---|
89 | return $Result;
|
---|
90 | }
|
---|
91 |
|
---|
92 | function AddChangeAction(): void
|
---|
93 | {
|
---|
94 | $Column = $this->AddEnum('ChangeAction', array('add', 'modify', 'remove'));
|
---|
95 | $Column->Nullable = true;
|
---|
96 | $Column = $this->AddDateTime('ChangeTime');
|
---|
97 | $Column->Nullable = true;
|
---|
98 | $this->AddInteger('ChangeReplaceId');
|
---|
99 | }
|
---|
100 | }
|
---|
101 |
|
---|
102 | class ModelColumnType
|
---|
103 | {
|
---|
104 | const Integer = 0;
|
---|
105 | const String = 1;
|
---|
106 | const Float = 2;
|
---|
107 | const Text = 3;
|
---|
108 | const DateTime = 4;
|
---|
109 | const Reference = 5;
|
---|
110 | const Boolean = 6;
|
---|
111 | const Date = 7;
|
---|
112 | const Enum = 8;
|
---|
113 | const BigInt = 9;
|
---|
114 |
|
---|
115 | static function GetName(int $Index)
|
---|
116 | {
|
---|
117 | $Text = array('Integer', 'String', 'Float', 'Text', 'DateTime', 'Reference', 'Boolean', 'Date', 'Enum', 'BigInt');
|
---|
118 | return $Text[$Index];
|
---|
119 | }
|
---|
120 | }
|
---|
121 |
|
---|
122 | class ModelColumn
|
---|
123 | {
|
---|
124 | public string $Name;
|
---|
125 | public int $Type; // ModelColumnType
|
---|
126 | public bool $Nullable;
|
---|
127 | public bool $Unique;
|
---|
128 | public bool $HasDefault;
|
---|
129 |
|
---|
130 | function __construct(string $Name, int $Type, bool $Nullable = false, bool $Unique = false)
|
---|
131 | {
|
---|
132 | $this->Name = $Name;
|
---|
133 | $this->Type = $Type;
|
---|
134 | $this->Nullable = $Nullable;
|
---|
135 | $this->Unique = $Unique;
|
---|
136 | $this->HasDefault = false;
|
---|
137 | }
|
---|
138 |
|
---|
139 | function GetDefault(): ?string
|
---|
140 | {
|
---|
141 | return null;
|
---|
142 | }
|
---|
143 | }
|
---|
144 |
|
---|
145 | class ModelColumnString extends ModelColumn
|
---|
146 | {
|
---|
147 | public ?string $Default;
|
---|
148 |
|
---|
149 | function __construct(string $Name)
|
---|
150 | {
|
---|
151 | parent::__construct($Name, ModelColumnType::String);
|
---|
152 | $this->HasDefault = false;
|
---|
153 | $this->Default = null;
|
---|
154 | }
|
---|
155 |
|
---|
156 | function GetDefault(): ?string
|
---|
157 | {
|
---|
158 | return '"'.$this->Default.'"';
|
---|
159 | }
|
---|
160 | }
|
---|
161 |
|
---|
162 | class ModelColumnFloat extends ModelColumn
|
---|
163 | {
|
---|
164 | public ?float $Default;
|
---|
165 |
|
---|
166 | function __construct(string $Name)
|
---|
167 | {
|
---|
168 | parent::__construct($Name, ModelColumnType::Float);
|
---|
169 | $this->HasDefault = false;
|
---|
170 | $this->Default = null;
|
---|
171 | }
|
---|
172 |
|
---|
173 | function GetDefault(): ?string
|
---|
174 | {
|
---|
175 | return '"'.$this->Default.'"';
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | class ModelColumnText extends ModelColumn
|
---|
180 | {
|
---|
181 | public ?string $Default;
|
---|
182 | public int $MaxLength;
|
---|
183 |
|
---|
184 | function __construct(string $Name)
|
---|
185 | {
|
---|
186 | parent::__construct($Name, ModelColumnType::Text);
|
---|
187 | $this->HasDefault = false;
|
---|
188 | $this->Default = null;
|
---|
189 | $this->MaxLength = 255;
|
---|
190 | }
|
---|
191 |
|
---|
192 | function GetDefault(): ?string
|
---|
193 | {
|
---|
194 | return '"'.$this->Default.'"';
|
---|
195 | }
|
---|
196 | }
|
---|
197 |
|
---|
198 | class ModelColumnInteger extends ModelColumn
|
---|
199 | {
|
---|
200 | public ?int $Default;
|
---|
201 |
|
---|
202 | function __construct(string $Name)
|
---|
203 | {
|
---|
204 | parent::__construct($Name, ModelColumnType::Integer);
|
---|
205 | $this->HasDefault = false;
|
---|
206 | $this->Default = null;
|
---|
207 | }
|
---|
208 |
|
---|
209 | function GetDefault(): ?string
|
---|
210 | {
|
---|
211 | return $this->Default;
|
---|
212 | }
|
---|
213 | }
|
---|
214 |
|
---|
215 | class ModelColumnBigInt extends ModelColumn
|
---|
216 | {
|
---|
217 | public ?int $Default;
|
---|
218 |
|
---|
219 | function __construct(string $Name)
|
---|
220 | {
|
---|
221 | parent::__construct($Name, ModelColumnType::BigInt);
|
---|
222 | $this->HasDefault = false;
|
---|
223 | $this->Default = null;
|
---|
224 | }
|
---|
225 |
|
---|
226 | function GetDefault(): ?string
|
---|
227 | {
|
---|
228 | return $this->Default;
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | class ModelColumnDateTime extends ModelColumn
|
---|
233 | {
|
---|
234 | public ?DateTime $Default;
|
---|
235 |
|
---|
236 | function __construct(string $Name)
|
---|
237 | {
|
---|
238 | parent::__construct($Name, ModelColumnType::DateTime);
|
---|
239 | $this->HasDefault = false;
|
---|
240 | $this->Default = null;
|
---|
241 | }
|
---|
242 |
|
---|
243 | function GetDefault(): ?string
|
---|
244 | {
|
---|
245 | return '"'.$this->Default.'"';
|
---|
246 | }
|
---|
247 | }
|
---|
248 |
|
---|
249 | class ModelColumnDate extends ModelColumn
|
---|
250 | {
|
---|
251 | public ?DateTime $Default;
|
---|
252 |
|
---|
253 | function __construct(string $Name)
|
---|
254 | {
|
---|
255 | parent::__construct($Name, ModelColumnType::Date);
|
---|
256 | $this->HasDefault = false;
|
---|
257 | $this->Default = null;
|
---|
258 | }
|
---|
259 |
|
---|
260 | function GetDefault(): ?string
|
---|
261 | {
|
---|
262 | return '"'.$this->Default.'"';
|
---|
263 | }
|
---|
264 | }
|
---|
265 |
|
---|
266 | class ModelColumnReference extends ModelColumn
|
---|
267 | {
|
---|
268 | public string $RefTable;
|
---|
269 |
|
---|
270 | function __construct(string $Name, string $RefTable)
|
---|
271 | {
|
---|
272 | parent::__construct($Name, ModelColumnType::Reference);
|
---|
273 | $this->RefTable = $RefTable;
|
---|
274 | }
|
---|
275 | }
|
---|
276 |
|
---|
277 | class ModelColumnBoolean extends ModelColumn
|
---|
278 | {
|
---|
279 | public ?bool $Default;
|
---|
280 |
|
---|
281 | function __construct(string $Name)
|
---|
282 | {
|
---|
283 | parent::__construct($Name, ModelColumnType::Boolean);
|
---|
284 | $this->HasDefault = false;
|
---|
285 | $this->Default = null;
|
---|
286 | }
|
---|
287 |
|
---|
288 | function GetDefault(): ?string
|
---|
289 | {
|
---|
290 | return $this->Default;
|
---|
291 | }
|
---|
292 | }
|
---|
293 |
|
---|
294 | class ModelColumnEnum extends ModelColumn
|
---|
295 | {
|
---|
296 | public ?bool $Default;
|
---|
297 | public array $States;
|
---|
298 |
|
---|
299 | function __construct(string $Name, array $States)
|
---|
300 | {
|
---|
301 | parent::__construct($Name, ModelColumnType::Enum);
|
---|
302 | $this->HasDefault = false;
|
---|
303 | $this->Default = null;
|
---|
304 | $this->States = $States;
|
---|
305 | }
|
---|
306 |
|
---|
307 | function GetDefault(): ?string
|
---|
308 | {
|
---|
309 | return $this->Default;
|
---|
310 | }
|
---|
311 | }
|
---|