1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Lagdo\DbAdmin\Driver; |
4
|
|
|
|
5
|
|
|
use Lagdo\DbAdmin\Driver\Entity\ConfigEntity; |
6
|
|
|
use Lagdo\DbAdmin\Driver\Entity\TableEntity; |
7
|
|
|
use Lagdo\DbAdmin\Driver\Entity\ForeignKeyEntity; |
8
|
|
|
use Lagdo\DbAdmin\Driver\Entity\TriggerEntity; |
9
|
|
|
use Lagdo\DbAdmin\Driver\Entity\RoutineEntity; |
10
|
|
|
|
11
|
|
|
use Lagdo\DbAdmin\Driver\Db\ConnectionInterface; |
12
|
|
|
|
13
|
|
|
trait DatabaseTrait |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* Create or alter table |
17
|
|
|
* |
18
|
|
|
* @param string $table "" to create |
19
|
|
|
* @param string $name new name |
20
|
|
|
* @param array $fields of array($orig, $process_field, $after) |
21
|
|
|
* @param array $foreign of strings |
22
|
|
|
* @param string $comment |
23
|
|
|
* @param string $engine |
24
|
|
|
* @param string $collation |
25
|
|
|
* @param int $autoIncrement number |
26
|
|
|
* @param string $partitioning |
27
|
|
|
* |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public function alterTable(string $table, string $name, array $fields, array $foreign, |
31
|
|
|
string $comment, string $engine, string $collation, int $autoIncrement, string $partitioning) |
32
|
|
|
{ |
33
|
|
|
return $this->database->alterTable($table, $name, $fields, $foreign, $comment, |
34
|
|
|
$engine, $collation, $autoIncrement, $partitioning); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Alter indexes |
39
|
|
|
* |
40
|
|
|
* @param string $table Escaped table name |
41
|
|
|
* @param array $alter array("index type", "name", array("column definition", ...)) or array("index type", "name", "DROP") |
42
|
|
|
* |
43
|
|
|
* @return bool |
44
|
|
|
*/ |
45
|
|
|
public function alterIndexes(string $table, array $alter) |
46
|
|
|
{ |
47
|
|
|
return $this->database->alterIndexes($table, $alter); |
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
|
|
|
* Get user defined types |
148
|
|
|
* |
149
|
|
|
* @return array |
150
|
|
|
*/ |
151
|
|
|
public function userTypes() |
152
|
|
|
{ |
153
|
|
|
return $this->database->userTypes(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get existing schemas |
158
|
|
|
* |
159
|
|
|
* @return array |
160
|
|
|
*/ |
161
|
|
|
public function schemas() |
162
|
|
|
{ |
163
|
|
|
return $this->database->schemas(); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Get events |
168
|
|
|
* |
169
|
|
|
* @return array |
170
|
|
|
*/ |
171
|
|
|
public function events() |
172
|
|
|
{ |
173
|
|
|
return $this->database->events(); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Get information about stored routine |
178
|
|
|
* |
179
|
|
|
* @param string $name |
180
|
|
|
* @param string $type "FUNCTION" or "PROCEDURE" |
181
|
|
|
* |
182
|
|
|
* @return RoutineEntity |
183
|
|
|
*/ |
184
|
|
|
public function routine(string $name, string $type) |
185
|
|
|
{ |
186
|
|
|
return $this->database->routine($name, $type); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* Get list of routines |
191
|
|
|
* |
192
|
|
|
* @return array |
193
|
|
|
*/ |
194
|
|
|
public function routines() |
195
|
|
|
{ |
196
|
|
|
return $this->database->routines(); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|