1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver; |
4
|
|
|
|
5
|
|
|
use Exception; |
6
|
|
|
use Lagdo\DbAdmin\Driver\Entity\TableEntity; |
7
|
|
|
use Lagdo\DbAdmin\Driver\Entity\RoutineEntity; |
8
|
|
|
|
9
|
|
|
trait DatabaseTrait |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Create table |
13
|
|
|
* |
14
|
|
|
* @param TableEntity $tableAttrs |
15
|
|
|
* |
16
|
|
|
* @return bool |
17
|
|
|
*/ |
18
|
|
|
public function createTable(TableEntity $tableAttrs) |
19
|
|
|
{ |
20
|
|
|
return $this->database->createTable($tableAttrs); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Alter table |
25
|
|
|
* |
26
|
|
|
* @param string $table |
27
|
|
|
* @param TableEntity $tableAttrs |
28
|
|
|
* |
29
|
|
|
* @return bool |
30
|
|
|
*/ |
31
|
|
|
public function alterTable(string $table, TableEntity $tableAttrs) |
32
|
|
|
{ |
33
|
|
|
return $this->database->alterTable($table, $tableAttrs); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Alter indexes |
38
|
|
|
* |
39
|
|
|
* @param string $table Escaped table name |
40
|
|
|
* @param array $alter Indexes to alter. Array of IndexEntity. |
41
|
|
|
* @param array $drop Indexes to drop. Array of IndexEntity. |
42
|
|
|
* |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function alterIndexes(string $table, array $alter, array $drop) |
46
|
|
|
{ |
47
|
|
|
return $this->database->alterIndexes($table, $alter, $drop); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get tables list |
52
|
|
|
* |
53
|
|
|
* @return array |
54
|
|
|
*/ |
55
|
|
|
public function tables() |
56
|
|
|
{ |
57
|
|
|
return $this->database->tables(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Get sequences list |
62
|
|
|
* |
63
|
|
|
* @return array |
64
|
|
|
*/ |
65
|
|
|
public function sequences() |
66
|
|
|
{ |
67
|
|
|
return $this->database->sequences(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Count tables in all databases |
72
|
|
|
* |
73
|
|
|
* @param array $databases |
74
|
|
|
* |
75
|
|
|
* @return array |
76
|
|
|
*/ |
77
|
|
|
public function countTables(array $databases) |
78
|
|
|
{ |
79
|
|
|
return $this->database->countTables($databases); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Drop views |
84
|
|
|
* |
85
|
|
|
* @param array $views |
86
|
|
|
* |
87
|
|
|
* @return bool |
88
|
|
|
*/ |
89
|
|
|
public function dropViews(array $views) |
90
|
|
|
{ |
91
|
|
|
return $this->database->dropViews($views); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Truncate tables |
96
|
|
|
* |
97
|
|
|
* @param array $tables |
98
|
|
|
* |
99
|
|
|
* @return bool |
100
|
|
|
*/ |
101
|
|
|
public function truncateTables(array $tables) |
102
|
|
|
{ |
103
|
|
|
return $this->database->truncateTables($tables); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Drop tables |
108
|
|
|
* |
109
|
|
|
* @param array $tables |
110
|
|
|
* |
111
|
|
|
* @return bool |
112
|
|
|
*/ |
113
|
|
|
public function dropTables(array $tables) |
114
|
|
|
{ |
115
|
|
|
return $this->database->dropTables($tables); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Move tables to other schema |
120
|
|
|
* |
121
|
|
|
* @param array $tables |
122
|
|
|
* @param array $views |
123
|
|
|
* @param string $target |
124
|
|
|
* |
125
|
|
|
* @return bool |
126
|
|
|
*/ |
127
|
|
|
public function moveTables(array $tables, array $views, string $target) |
128
|
|
|
{ |
129
|
|
|
return $this->database->moveTables($tables, $views, $target); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Copy tables to other schema |
134
|
|
|
* |
135
|
|
|
* @param array $tables |
136
|
|
|
* @param array $views |
137
|
|
|
* @param string $target |
138
|
|
|
* |
139
|
|
|
* @return bool |
140
|
|
|
*/ |
141
|
|
|
public function copyTables(array $tables, array $views, string $target) |
142
|
|
|
{ |
143
|
|
|
return $this->database->copyTables($tables, $views, $target); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Create a view |
148
|
|
|
* |
149
|
|
|
* @param array $values The view values |
150
|
|
|
* |
151
|
|
|
* @return bool |
152
|
|
|
* @throws Exception |
153
|
|
|
*/ |
154
|
|
|
public function createView(array $values) |
155
|
|
|
{ |
156
|
|
|
return $this->database->createView($values); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Update a view |
161
|
|
|
* |
162
|
|
|
* @param string $view The view name |
163
|
|
|
* @param array $values The view values |
164
|
|
|
* |
165
|
|
|
* @return string |
166
|
|
|
* @throws Exception |
167
|
|
|
*/ |
168
|
|
|
public function updateView(string $view, array $values): string |
169
|
|
|
{ |
170
|
|
|
return $this->database->updateView($view, $values); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* Drop a view |
175
|
|
|
* |
176
|
|
|
* @param string $view The view name |
177
|
|
|
* |
178
|
|
|
* @return bool |
179
|
|
|
* @throws Exception |
180
|
|
|
*/ |
181
|
|
|
public function dropView(string $view): bool |
182
|
|
|
{ |
183
|
|
|
return $this->database->dropView($view); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Get user defined types |
188
|
|
|
* |
189
|
|
|
* @return array |
190
|
|
|
*/ |
191
|
|
|
public function userTypes() |
192
|
|
|
{ |
193
|
|
|
return $this->database->userTypes(); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
/** |
197
|
|
|
* Get existing schemas |
198
|
|
|
* |
199
|
|
|
* @return array |
200
|
|
|
*/ |
201
|
|
|
public function schemas() |
202
|
|
|
{ |
203
|
|
|
return $this->database->schemas(); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Get events |
208
|
|
|
* |
209
|
|
|
* @return array |
210
|
|
|
*/ |
211
|
|
|
public function events() |
212
|
|
|
{ |
213
|
|
|
return $this->database->events(); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* Get information about stored routine |
218
|
|
|
* |
219
|
|
|
* @param string $name |
220
|
|
|
* @param string $type "FUNCTION" or "PROCEDURE" |
221
|
|
|
* |
222
|
|
|
* @return RoutineEntity |
223
|
|
|
*/ |
224
|
|
|
public function routine(string $name, string $type) |
225
|
|
|
{ |
226
|
|
|
return $this->database->routine($name, $type); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Get list of routines |
231
|
|
|
* |
232
|
|
|
* @return array |
233
|
|
|
*/ |
234
|
|
|
public function routines() |
235
|
|
|
{ |
236
|
|
|
return $this->database->routines(); |
237
|
|
|
} |
238
|
|
|
} |
239
|
|
|
|