DatabaseTrait   A
last analyzed

Complexity

Total Complexity 20

Size/Duplication

Total Lines 246
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 246
rs 10
wmc 20

20 Methods

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