@@ -27,8 +27,8 @@ discard block |
||
27 | 27 | $table = $temp[1]; |
28 | 28 | } |
29 | 29 | |
30 | - if (isset($tables[$schema . '.' . $table])) { |
|
31 | - return $tables[$schema . '.' . $table]; |
|
30 | + if (isset($tables[$schema.'.'.$table])) { |
|
31 | + return $tables[$schema.'.'.$table]; |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | static $comments = []; |
@@ -36,10 +36,10 @@ discard block |
||
36 | 36 | $comments[$schema] = Collection::from( |
37 | 37 | $this->query( |
38 | 38 | "SELECT TABLE_NAME, TABLE_COMMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ?", |
39 | - [ $schema ] |
|
39 | + [$schema] |
|
40 | 40 | ) |
41 | 41 | ) |
42 | - ->mapKey(function (array $v): string { |
|
42 | + ->mapKey(function(array $v): string { |
|
43 | 43 | return $v['TABLE_NAME']; |
44 | 44 | }) |
45 | 45 | ->pluck('TABLE_COMMENT') |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | WHERE |
62 | 62 | (TABLE_SCHEMA = ? OR REFERENCED_TABLE_SCHEMA = ?) AND |
63 | 63 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
64 | - [ $main, $main ] |
|
64 | + [$main, $main] |
|
65 | 65 | ) |
66 | 66 | )->toArray(); |
67 | 67 | foreach ($col as $row) { |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | if ($row['REFERENCED_TABLE_SCHEMA'] !== $main) { |
72 | 72 | $additional[] = $row['REFERENCED_TABLE_SCHEMA']; |
73 | 73 | } |
74 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
75 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
74 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
75 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
76 | 76 | } |
77 | 77 | foreach (array_filter(array_unique($additional)) as $s) { |
78 | 78 | $col = Collection::from( |
@@ -84,12 +84,12 @@ discard block |
||
84 | 84 | WHERE |
85 | 85 | TABLE_SCHEMA = ? AND REFERENCED_TABLE_SCHEMA = ? AND |
86 | 86 | TABLE_NAME IS NOT NULL AND REFERENCED_TABLE_NAME IS NOT NULL", |
87 | - [ $s, $s ] |
|
87 | + [$s, $s] |
|
88 | 88 | ) |
89 | 89 | )->toArray(); |
90 | 90 | foreach ($col as $row) { |
91 | - $relationsT[$row['TABLE_SCHEMA'] . '.' . $row['TABLE_NAME']][] = $row; |
|
92 | - $relationsR[$row['REFERENCED_TABLE_SCHEMA'] . '.' . $row['REFERENCED_TABLE_NAME']][] = $row; |
|
91 | + $relationsT[$row['TABLE_SCHEMA'].'.'.$row['TABLE_NAME']][] = $row; |
|
92 | + $relationsR[$row['REFERENCED_TABLE_SCHEMA'].'.'.$row['REFERENCED_TABLE_NAME']][] = $row; |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -98,14 +98,14 @@ discard block |
||
98 | 98 | if (!count($columns)) { |
99 | 99 | throw new DBException('Table not found by name'); |
100 | 100 | } |
101 | - $tables[$schema . '.' . $table] = $definition = (new Table($table, $schema)) |
|
101 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
102 | 102 | ->addColumns( |
103 | 103 | $columns |
104 | 104 | ->clone() |
105 | - ->mapKey(function (array $v): string { |
|
105 | + ->mapKey(function(array $v): string { |
|
106 | 106 | return $v['Field']; |
107 | 107 | }) |
108 | - ->map(function (array $v): array { |
|
108 | + ->map(function(array $v): array { |
|
109 | 109 | $v['length'] = null; |
110 | 110 | if (!isset($v['Type'])) { |
111 | 111 | return $v; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | default: |
128 | 128 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
129 | 129 | // extract length from varchar |
130 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
130 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
131 | 131 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
132 | 132 | } |
133 | 133 | break; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | ->setPrimaryKey( |
140 | 140 | $columns |
141 | 141 | ->clone() |
142 | - ->filter(function (array $v): bool { |
|
142 | + ->filter(function(array $v): bool { |
|
143 | 143 | return $v['Key'] === 'PRI'; |
144 | 144 | }) |
145 | 145 | ->pluck('Field') |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | // assuming current table is linked to "one" record in the referenced table |
154 | 154 | // resulting in a "belongsTo" relationship |
155 | 155 | $relations = []; |
156 | - foreach (Collection::from($relationsT[$schema . '.' . $table] ?? []) |
|
157 | - ->map(function (array $v): array { |
|
156 | + foreach (Collection::from($relationsT[$schema.'.'.$table] ?? []) |
|
157 | + ->map(function(array $v): array { |
|
158 | 158 | $new = []; |
159 | 159 | foreach ($v as $kk => $vv) { |
160 | 160 | $new[strtoupper($kk)] = $vv; |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | return $new; |
163 | 163 | }) as $relation |
164 | 164 | ) { |
165 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . |
|
165 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'. |
|
166 | 166 | $relation['REFERENCED_TABLE_NAME']; |
167 | 167 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
168 | 168 | $relation['REFERENCED_COLUMN_NAME']; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $orig = $relname; |
177 | 177 | $cntr = 1; |
178 | 178 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
179 | - $relname = $orig . '_' . (++ $cntr); |
|
179 | + $relname = $orig.'_'.(++$cntr); |
|
180 | 180 | } |
181 | 181 | $definition->addRelation( |
182 | 182 | new TableRelation( |
@@ -192,13 +192,13 @@ discard block |
||
192 | 192 | // assuming current table is on the "one" end having "many" records in the referencing table |
193 | 193 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
194 | 194 | $relations = []; |
195 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
196 | - $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'] . '.' . |
|
195 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
196 | + $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_SCHEMA'].'.'. |
|
197 | 197 | $relation['TABLE_NAME']; |
198 | 198 | $relations[$relation['CONSTRAINT_NAME']]['keymap'][$relation['REFERENCED_COLUMN_NAME']] = |
199 | 199 | $relation['COLUMN_NAME']; |
200 | 200 | } |
201 | - foreach ([ true, false ] as $pivot) { |
|
201 | + foreach ([true, false] as $pivot) { |
|
202 | 202 | foreach ($relations as $data) { |
203 | 203 | $rtable = $this->table($data['table'], true); |
204 | 204 | $columns = []; |
@@ -211,10 +211,10 @@ discard block |
||
211 | 211 | $usedcol = []; |
212 | 212 | if (count($columns)) { |
213 | 213 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
214 | - ->filter(function (array $v) use ($columns): bool { |
|
214 | + ->filter(function(array $v) use ($columns): bool { |
|
215 | 215 | return in_array($v['COLUMN_NAME'], $columns); |
216 | 216 | }) |
217 | - ->map(function (array $v): array { |
|
217 | + ->map(function(array $v): array { |
|
218 | 218 | $new = []; |
219 | 219 | foreach ($v as $kk => $vv) { |
220 | 220 | $new[strtoupper($kk)] = $vv; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | return $new; |
223 | 223 | }) as $relation |
224 | 224 | ) { |
225 | - $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'] . '.' . |
|
225 | + $foreign[$relation['CONSTRAINT_NAME']]['table'] = $relation['REFERENCED_TABLE_SCHEMA'].'.'. |
|
226 | 226 | $relation['REFERENCED_TABLE_NAME']; |
227 | 227 | $foreign[$relation['CONSTRAINT_NAME']]['keymap'][$relation['COLUMN_NAME']] = |
228 | 228 | $relation['REFERENCED_COLUMN_NAME']; |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | $orig = $relname; |
240 | 240 | $cntr = 1; |
241 | 241 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
242 | - $relname = $orig . '_' . (++ $cntr); |
|
242 | + $relname = $orig.'_'.(++$cntr); |
|
243 | 243 | } |
244 | 244 | $definition->addRelation( |
245 | 245 | new TableRelation( |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | $orig = $relname; |
266 | 266 | $cntr = 1; |
267 | 267 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
268 | - $relname = $orig . '_' . (++ $cntr); |
|
268 | + $relname = $orig.'_'.(++$cntr); |
|
269 | 269 | } |
270 | 270 | $definition->addRelation( |
271 | 271 | new TableRelation( |
@@ -294,23 +294,23 @@ discard block |
||
294 | 294 | "SELECT table_name FROM information_schema.tables where table_schema = ?", |
295 | 295 | [$this->connection['opts']['schema'] ?? $this->connection['name']] |
296 | 296 | )) |
297 | - ->map(function (array $v): array { |
|
297 | + ->map(function(array $v): array { |
|
298 | 298 | $new = []; |
299 | 299 | foreach ($v as $kk => $vv) { |
300 | 300 | $new[strtoupper($kk)] = $vv; |
301 | 301 | } |
302 | 302 | return $new; |
303 | 303 | }) |
304 | - ->mapKey(function (array $v): string { |
|
304 | + ->mapKey(function(array $v): string { |
|
305 | 305 | return strtolower($v['TABLE_NAME']); |
306 | 306 | }) |
307 | 307 | ->pluck('TABLE_NAME') |
308 | - ->map(function (string $v): Table { |
|
308 | + ->map(function(string $v): Table { |
|
309 | 309 | return $this->table($v)->toLowerCase(); |
310 | 310 | }) |
311 | 311 | ->toArray(); |
312 | 312 | foreach (array_keys($tables) as $k) { |
313 | - $tables[($this->connection['opts']['schema'] ?? $this->connection['name']) . '.' . $k] = &$tables[$k]; |
|
313 | + $tables[($this->connection['opts']['schema'] ?? $this->connection['name']).'.'.$k] = &$tables[$k]; |
|
314 | 314 | } |
315 | 315 | return $tables; |
316 | 316 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | $table = $temp[1]; |
30 | 30 | } |
31 | 31 | |
32 | - if (isset($tables[$schema . '.' . $table])) { |
|
33 | - return $tables[$schema . '.' . $table]; |
|
32 | + if (isset($tables[$schema.'.'.$table])) { |
|
33 | + return $tables[$schema.'.'.$table]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | static $relationsT = null; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | (kc.table_schema = ? OR ct.table_schema = ?) AND |
62 | 62 | kc.table_name IS NOT NULL AND |
63 | 63 | kc.position_in_unique_constraint IS NOT NULL", |
64 | - [ $catalog, $main, $main ] |
|
64 | + [$catalog, $main, $main] |
|
65 | 65 | ) |
66 | 66 | )->toArray(); |
67 | 67 | foreach ($col as $row) { |
@@ -71,8 +71,8 @@ discard block |
||
71 | 71 | if ($row['referenced_table_schema'] !== $main) { |
72 | 72 | $additional[] = $row['referenced_table_schema']; |
73 | 73 | } |
74 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
75 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
74 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
75 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
76 | 76 | } |
77 | 77 | foreach (array_filter(array_unique($additional)) as $s) { |
78 | 78 | $col = Collection::from( |
@@ -97,12 +97,12 @@ discard block |
||
97 | 97 | (kc.table_schema = ? AND ct.table_schema = ?) AND |
98 | 98 | kc.table_name IS NOT NULL AND |
99 | 99 | kc.position_in_unique_constraint IS NOT NULL", |
100 | - [ $catalog, $s, $s ] |
|
100 | + [$catalog, $s, $s] |
|
101 | 101 | ) |
102 | 102 | )->toArray(); |
103 | 103 | foreach ($col as $row) { |
104 | - $relationsT[$row['table_schema'] . '.' . $row['table_name']][] = $row; |
|
105 | - $relationsR[$row['referenced_table_schema'] . '.' . $row['referenced_table_name']][] = $row; |
|
104 | + $relationsT[$row['table_schema'].'.'.$row['table_name']][] = $row; |
|
105 | + $relationsR[$row['referenced_table_schema'].'.'.$row['referenced_table_name']][] = $row; |
|
106 | 106 | } |
107 | 107 | } |
108 | 108 | } |
@@ -114,12 +114,12 @@ discard block |
||
114 | 114 | ->query( |
115 | 115 | "SELECT * FROM information_schema.columns |
116 | 116 | WHERE table_name = ? AND table_schema = ? AND table_catalog = ?", |
117 | - [ $table, $schema, $catalog ] |
|
117 | + [$table, $schema, $catalog] |
|
118 | 118 | )) |
119 | - ->mapKey(function ($v): string { |
|
119 | + ->mapKey(function($v): string { |
|
120 | 120 | return $v['column_name']; |
121 | 121 | }) |
122 | - ->map(function ($v) { |
|
122 | + ->map(function($v) { |
|
123 | 123 | $v['length'] = null; |
124 | 124 | if (!isset($v['data_type'])) { |
125 | 125 | return $v; |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | switch ($v['data_type']) { |
128 | 128 | case 'character': |
129 | 129 | case 'character varying': |
130 | - $v['length'] = (int)$v['character_maximum_length']; |
|
130 | + $v['length'] = (int) $v['character_maximum_length']; |
|
131 | 131 | break; |
132 | 132 | } |
133 | 133 | $v['hidden'] = $v['is_identity'] !== 'YES' && $v['is_generated'] === 'ALWAYS'; |
@@ -135,13 +135,13 @@ discard block |
||
135 | 135 | }) |
136 | 136 | ->toArray(); |
137 | 137 | if (!count($columns)) { |
138 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
138 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
139 | 139 | } |
140 | 140 | $pkname = Collection::from($this |
141 | 141 | ->query( |
142 | 142 | "SELECT constraint_name FROM information_schema.table_constraints |
143 | 143 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
144 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
144 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
145 | 145 | )) |
146 | 146 | ->pluck('constraint_name') |
147 | 147 | ->value(); |
@@ -151,12 +151,12 @@ discard block |
||
151 | 151 | ->query( |
152 | 152 | "SELECT column_name FROM information_schema.constraint_column_usage |
153 | 153 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
154 | - [ $table, $pkname, $schema, $catalog ] |
|
154 | + [$table, $pkname, $schema, $catalog] |
|
155 | 155 | )) |
156 | 156 | ->pluck('column_name') |
157 | 157 | ->toArray(); |
158 | 158 | } |
159 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
159 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
160 | 160 | ->addColumns($columns) |
161 | 161 | ->setPrimaryKey($primary) |
162 | 162 | ->setComment(''); |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | // assuming current table is linked to "one" record in the referenced table |
167 | 167 | // resulting in a "belongsTo" relationship |
168 | 168 | $relations = []; |
169 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
170 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
169 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
170 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
171 | 171 | $relation['referenced_table_name']; |
172 | 172 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
173 | 173 | $relation['referenced_column_name']; |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | $definition->getName() == $relname || |
185 | 185 | $definition->getColumn($relname) |
186 | 186 | ) { |
187 | - $relname = $orig . '_' . (++ $cntr); |
|
187 | + $relname = $orig.'_'.(++$cntr); |
|
188 | 188 | } |
189 | 189 | $definition->addRelation( |
190 | 190 | new TableRelation( |
@@ -200,13 +200,13 @@ discard block |
||
200 | 200 | // assuming current table is on the "one" end having "many" records in the referencing table |
201 | 201 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
202 | 202 | $relations = []; |
203 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
204 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
203 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
204 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
205 | 205 | $relation['table_name']; |
206 | 206 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
207 | 207 | $relation['column_name']; |
208 | 208 | } |
209 | - foreach ([ true, false ] as $pivot) { |
|
209 | + foreach ([true, false] as $pivot) { |
|
210 | 210 | foreach ($relations as $data) { |
211 | 211 | $rtable = $this->table($data['table'], true); |
212 | 212 | $columns = []; |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | $usedcol = []; |
220 | 220 | if (count($columns)) { |
221 | 221 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
222 | - ->filter(function ($v) use ($columns) { |
|
222 | + ->filter(function($v) use ($columns) { |
|
223 | 223 | return in_array($v['column_name'], $columns); |
224 | 224 | }) as $relation |
225 | 225 | ) { |
226 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
226 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
227 | 227 | $relation['referenced_table_name']; |
228 | 228 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
229 | 229 | $relation['referenced_column_name']; |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $definition->getName() == $relname || |
244 | 244 | $definition->getColumn($relname) |
245 | 245 | ) { |
246 | - $relname = $orig . '_' . (++ $cntr); |
|
246 | + $relname = $orig.'_'.(++$cntr); |
|
247 | 247 | } |
248 | 248 | $definition->addRelation( |
249 | 249 | new TableRelation( |
@@ -272,7 +272,7 @@ discard block |
||
272 | 272 | $definition->getName() == $relname || |
273 | 273 | $definition->getColumn($relname) |
274 | 274 | ) { |
275 | - $relname = $orig . '_' . (++ $cntr); |
|
275 | + $relname = $orig.'_'.(++$cntr); |
|
276 | 276 | } |
277 | 277 | $definition->addRelation( |
278 | 278 | new TableRelation( |
@@ -323,20 +323,20 @@ discard block |
||
323 | 323 | attr.attnum > 0 |
324 | 324 | order by |
325 | 325 | attr.attnum", |
326 | - [ $table, $schema ] |
|
326 | + [$table, $schema] |
|
327 | 327 | )) |
328 | - ->mapKey(function ($v): string { |
|
328 | + ->mapKey(function($v): string { |
|
329 | 329 | return $v['column_name']; |
330 | 330 | }) |
331 | - ->map(function ($v) { |
|
331 | + ->map(function($v) { |
|
332 | 332 | $v['length'] = null; |
333 | 333 | return $v; |
334 | 334 | }) |
335 | 335 | ->toArray(); |
336 | 336 | if (!count($columns)) { |
337 | - throw new DBException('View not found by name: ' . implode('.', [$schema,$table])); |
|
337 | + throw new DBException('View not found by name: '.implode('.', [$schema, $table])); |
|
338 | 338 | } |
339 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
339 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
340 | 340 | ->addColumns($columns) |
341 | 341 | ->setComment(''); |
342 | 342 | return $definition; |
@@ -346,13 +346,13 @@ discard block |
||
346 | 346 | $tables = Collection::from($this |
347 | 347 | ->query( |
348 | 348 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
349 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
349 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
350 | 350 | )) |
351 | - ->mapKey(function ($v) { |
|
351 | + ->mapKey(function($v) { |
|
352 | 352 | return strtolower($v['table_name']); |
353 | 353 | }) |
354 | 354 | ->pluck('table_name') |
355 | - ->map(function ($v) { |
|
355 | + ->map(function($v) { |
|
356 | 356 | return $this->table($v)->toLowerCase(); |
357 | 357 | }) |
358 | 358 | ->toArray(); |
@@ -363,19 +363,19 @@ discard block |
||
363 | 363 | FROM pg_catalog.pg_class cls |
364 | 364 | join pg_catalog.pg_namespace as ns on ns.oid = cls.relnamespace |
365 | 365 | WHERE cls.relkind = 'm' and ns.nspname = ?", |
366 | - [ $this->connection['opts']['schema'] ?? 'public' ] |
|
366 | + [$this->connection['opts']['schema'] ?? 'public'] |
|
367 | 367 | )) |
368 | - ->mapKey(function ($v) { |
|
368 | + ->mapKey(function($v) { |
|
369 | 369 | return strtolower($v['table_name']); |
370 | 370 | }) |
371 | 371 | ->pluck('table_name') |
372 | - ->map(function ($v) { |
|
372 | + ->map(function($v) { |
|
373 | 373 | return $this->view($v)->toLowerCase(); |
374 | 374 | }) |
375 | 375 | ->toArray(); |
376 | 376 | $tables = array_merge($views, $tables); |
377 | 377 | foreach (array_keys($tables) as $k) { |
378 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
378 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
379 | 379 | } |
380 | 380 | return $tables; |
381 | 381 | } |
@@ -29,8 +29,8 @@ discard block |
||
29 | 29 | $table = $temp[1]; |
30 | 30 | } |
31 | 31 | |
32 | - if (isset($tables[$schema . '.' . $table])) { |
|
33 | - return $tables[$schema . '.' . $table]; |
|
32 | + if (isset($tables[$schema.'.'.$table])) { |
|
33 | + return $tables[$schema.'.'.$table]; |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | static $relationsT = null; |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | ] |
54 | 54 | ) |
55 | 55 | ); |
56 | - $relationsT['main.' . $row['table']][] = $row; |
|
57 | - $relationsR['main.' . $row['referenced_table']][] = $row; |
|
56 | + $relationsT['main.'.$row['table']][] = $row; |
|
57 | + $relationsR['main.'.$row['referenced_table']][] = $row; |
|
58 | 58 | } |
59 | 59 | } |
60 | 60 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | */ |
65 | 65 | $columns = Collection::from($this |
66 | 66 | ->query("PRAGMA table_info(".$table.")")) |
67 | - ->mapKey(function ($v): string { |
|
67 | + ->mapKey(function($v): string { |
|
68 | 68 | return $v['name']; |
69 | 69 | }) |
70 | - ->map(function ($v) { |
|
70 | + ->map(function($v) { |
|
71 | 71 | $v['length'] = null; |
72 | 72 | if (!isset($v['type'])) { |
73 | 73 | return $v; |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | default: |
78 | 78 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
79 | 79 | // extract length from varchar |
80 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
80 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
81 | 81 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
82 | 82 | } |
83 | 83 | break; |
@@ -86,15 +86,15 @@ discard block |
||
86 | 86 | }) |
87 | 87 | ->toArray(); |
88 | 88 | if (!count($columns)) { |
89 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
89 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
90 | 90 | } |
91 | 91 | $primary = []; |
92 | 92 | foreach ($columns as $column) { |
93 | - if ((int)$column['pk']) { |
|
93 | + if ((int) $column['pk']) { |
|
94 | 94 | $primary[] = $column['name']; |
95 | 95 | } |
96 | 96 | } |
97 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
97 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
98 | 98 | ->addColumns($columns) |
99 | 99 | ->setPrimaryKey($primary) |
100 | 100 | ->setComment(''); |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | // assuming current table is linked to "one" record in the referenced table |
105 | 105 | // resulting in a "belongsTo" relationship |
106 | 106 | $relations = []; |
107 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
108 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table']; |
|
107 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
108 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table']; |
|
109 | 109 | $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
110 | 110 | } |
111 | 111 | foreach ($relations as $name => $data) { |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | $definition->getName() == $relname || |
121 | 121 | $definition->getColumn($relname) |
122 | 122 | ) { |
123 | - $relname = $orig . '_' . (++ $cntr); |
|
123 | + $relname = $orig.'_'.(++$cntr); |
|
124 | 124 | } |
125 | 125 | $definition->addRelation( |
126 | 126 | new TableRelation( |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | // assuming current table is on the "one" end having "many" records in the referencing table |
137 | 137 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
138 | 138 | $relations = []; |
139 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) { |
|
140 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table']; |
|
139 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) { |
|
140 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table']; |
|
141 | 141 | $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from']; |
142 | 142 | } |
143 | - foreach ([ true, false ] as $pivot) { |
|
143 | + foreach ([true, false] as $pivot) { |
|
144 | 144 | foreach ($relations as $data) { |
145 | 145 | $rtable = $this->table($data['table'], true); |
146 | 146 | $columns = []; |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | $usedcol = []; |
154 | 154 | if (count($columns)) { |
155 | 155 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
156 | - ->filter(function ($v) use ($columns) { |
|
156 | + ->filter(function($v) use ($columns) { |
|
157 | 157 | return in_array($v['from'], $columns); |
158 | 158 | }) as $relation |
159 | 159 | ) { |
160 | - $foreign[$relation['constraint_name']]['table'] = 'main.' . |
|
160 | + $foreign[$relation['constraint_name']]['table'] = 'main.'. |
|
161 | 161 | $relation['referenced_table']; |
162 | 162 | $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
163 | 163 | $usedcol[] = $relation['from']; |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | $definition->getName() == $relname || |
177 | 177 | $definition->getColumn($relname) |
178 | 178 | ) { |
179 | - $relname = $orig . '_' . (++ $cntr); |
|
179 | + $relname = $orig.'_'.(++$cntr); |
|
180 | 180 | } |
181 | 181 | $definition->addRelation( |
182 | 182 | new TableRelation( |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $definition->getName() == $relname || |
206 | 206 | $definition->getColumn($relname) |
207 | 207 | ) { |
208 | - $relname = $orig . '_' . (++ $cntr); |
|
208 | + $relname = $orig.'_'.(++$cntr); |
|
209 | 209 | } |
210 | 210 | $definition->addRelation( |
211 | 211 | new TableRelation( |
@@ -234,9 +234,9 @@ discard block |
||
234 | 234 | "SELECT tbl_name |
235 | 235 | FROM sqlite_schema |
236 | 236 | WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';", |
237 | - [ 'table', 'view' ] |
|
237 | + ['table', 'view'] |
|
238 | 238 | )) |
239 | - ->mapKey(function ($v) { |
|
239 | + ->mapKey(function($v) { |
|
240 | 240 | return strtolower($v['tbl_name']); |
241 | 241 | }) |
242 | 242 | ->pluck('tbl_name') |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase(); |
246 | 246 | } |
247 | 247 | foreach (array_keys($tables) as $k) { |
248 | - $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k]; |
|
248 | + $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k]; |
|
249 | 249 | } |
250 | 250 | return $tables; |
251 | 251 | } |
@@ -32,19 +32,19 @@ discard block |
||
32 | 32 | $columns = Collection::from($this |
33 | 33 | ->query( |
34 | 34 | "SELECT * FROM user_tab_cols WHERE UPPER(table_name) = ?", |
35 | - [ strtoupper($table) ] |
|
35 | + [strtoupper($table)] |
|
36 | 36 | )) |
37 | - ->map(function ($v) { |
|
37 | + ->map(function($v) { |
|
38 | 38 | $new = []; |
39 | 39 | foreach ($v as $kk => $vv) { |
40 | 40 | $new[strtoupper($kk)] = $vv; |
41 | 41 | } |
42 | 42 | return $new; |
43 | 43 | }) |
44 | - ->mapKey(function ($v): string { |
|
44 | + ->mapKey(function($v): string { |
|
45 | 45 | return $v['COLUMN_NAME']; |
46 | 46 | }) |
47 | - ->map(function ($v) { |
|
47 | + ->map(function($v) { |
|
48 | 48 | $v['length'] = null; |
49 | 49 | if (!isset($v['DATA_TYPE'])) { |
50 | 50 | return $v; |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | default: |
57 | 57 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
58 | 58 | // extract length from varchar |
59 | - $v['length'] = (int)explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
59 | + $v['length'] = (int) explode(')', (explode('(', $type)[1] ?? ''))[0]; |
|
60 | 60 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
61 | 61 | } |
62 | 62 | break; |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | ->query( |
74 | 74 | "SELECT constraint_name FROM user_constraints |
75 | 75 | WHERE table_name = ? AND constraint_type = ?", |
76 | - [ strtoupper($table), 'P' ] |
|
76 | + [strtoupper($table), 'P'] |
|
77 | 77 | )) |
78 | - ->map(function ($v) { |
|
78 | + ->map(function($v) { |
|
79 | 79 | $new = []; |
80 | 80 | foreach ($v as $kk => $vv) { |
81 | 81 | $new[strtoupper($kk)] = $vv; |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | ->query( |
91 | 91 | "SELECT column_name FROM user_cons_columns |
92 | 92 | WHERE table_name = ? AND constraint_name = ?", |
93 | - [ strtoupper($table), $pkname ] |
|
93 | + [strtoupper($table), $pkname] |
|
94 | 94 | )) |
95 | - ->map(function ($v) { |
|
95 | + ->map(function($v) { |
|
96 | 96 | $new = []; |
97 | 97 | foreach ($v as $kk => $vv) { |
98 | 98 | $new[strtoupper($kk)] = $vv; |
@@ -124,9 +124,9 @@ discard block |
||
124 | 124 | LEFT JOIN user_cons_columns cc ON cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
125 | 125 | WHERE ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
126 | 126 | ORDER BY cc.POSITION", |
127 | - [ strtoupper($table), 'R' ] |
|
127 | + [strtoupper($table), 'R'] |
|
128 | 128 | )) |
129 | - ->map(function ($v) { |
|
129 | + ->map(function($v) { |
|
130 | 130 | $new = []; |
131 | 131 | foreach ($v as $kk => $vv) { |
132 | 132 | $new[strtoupper($kk)] = $vv; |
@@ -144,9 +144,9 @@ discard block |
||
144 | 144 | ->query( |
145 | 145 | "SELECT COLUMN_NAME FROM user_cons_columns |
146 | 146 | WHERE CONSTRAINT_NAME = ? ORDER BY POSITION", |
147 | - [ current($data['keymap']) ] |
|
147 | + [current($data['keymap'])] |
|
148 | 148 | )) |
149 | - ->map(function ($v) { |
|
149 | + ->map(function($v) { |
|
150 | 150 | $new = []; |
151 | 151 | foreach ($v as $kk => $vv) { |
152 | 152 | $new[strtoupper($kk)] = $vv; |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | $relname = $data['table']; |
162 | 162 | $cntr = 1; |
163 | 163 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
164 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
164 | + $relname = $data['table'].'_'.(++$cntr); |
|
165 | 165 | } |
166 | 166 | $definition->addRelation( |
167 | 167 | new TableRelation( |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | WHERE |
186 | 186 | ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
187 | 187 | ORDER BY cc.POSITION", |
188 | - [ $pkname, 'R' ] |
|
188 | + [$pkname, 'R'] |
|
189 | 189 | )) |
190 | - ->map(function ($v) { |
|
190 | + ->map(function($v) { |
|
191 | 191 | $new = []; |
192 | 192 | foreach ($v as $kk => $vv) { |
193 | 193 | $new[strtoupper($kk)] = $vv; |
@@ -197,10 +197,10 @@ discard block |
||
197 | 197 | as $relation |
198 | 198 | ) { |
199 | 199 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
200 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
|
200 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = |
|
201 | 201 | $relation['COLUMN_NAME']; |
202 | 202 | } |
203 | - foreach ([ true, false ] as $pivot) { |
|
203 | + foreach ([true, false] as $pivot) { |
|
204 | 204 | foreach ($relations as $data) { |
205 | 205 | $rtable = $this->table($data['table'], true); |
206 | 206 | $columns = []; |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
229 | 229 | cc.COLUMN_NAME IN (??) |
230 | 230 | ORDER BY POSITION", |
231 | - [ $data['table'], 'R', $columns ] |
|
231 | + [$data['table'], 'R', $columns] |
|
232 | 232 | )) |
233 | - ->map(function ($v) { |
|
233 | + ->map(function($v) { |
|
234 | 234 | $new = []; |
235 | 235 | foreach ($v as $kk => $vv) { |
236 | 236 | $new[strtoupper($kk)] = $vv; |
@@ -250,9 +250,9 @@ discard block |
||
250 | 250 | ->query( |
251 | 251 | "SELECT COLUMN_NAME FROM user_cons_columns |
252 | 252 | WHERE CONSTRAINT_NAME = ? ORDER BY POSITION", |
253 | - [ current($foreign['keymap']) ] |
|
253 | + [current($foreign['keymap'])] |
|
254 | 254 | )) |
255 | - ->map(function ($v) { |
|
255 | + ->map(function($v) { |
|
256 | 256 | $new = []; |
257 | 257 | foreach ($v as $kk => $vv) { |
258 | 258 | $new[strtoupper($kk)] = $vv; |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | $relname = $foreign['table']; |
268 | 268 | $cntr = 1; |
269 | 269 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
270 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
270 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
271 | 271 | } |
272 | 272 | $definition->addRelation( |
273 | 273 | new TableRelation( |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | $relname = $data['table']; |
289 | 289 | $cntr = 1; |
290 | 290 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
291 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
291 | + $relname = $data['table'].'_'.(++$cntr); |
|
292 | 292 | } |
293 | 293 | $definition->addRelation( |
294 | 294 | new TableRelation( |
@@ -319,18 +319,18 @@ discard block |
||
319 | 319 | SELECT VIEW_NAME AS TABLE_NAME FROM USER_VIEWS", |
320 | 320 | [] |
321 | 321 | )) |
322 | - ->map(function ($v) { |
|
322 | + ->map(function($v) { |
|
323 | 323 | $new = []; |
324 | 324 | foreach ($v as $kk => $vv) { |
325 | 325 | $new[strtoupper($kk)] = $vv; |
326 | 326 | } |
327 | 327 | return $new; |
328 | 328 | }) |
329 | - ->mapKey(function ($v) { |
|
329 | + ->mapKey(function($v) { |
|
330 | 330 | return strtolower($v['TABLE_NAME']); |
331 | 331 | }) |
332 | 332 | ->pluck('TABLE_NAME') |
333 | - ->map(function ($v) { |
|
333 | + ->map(function($v) { |
|
334 | 334 | return $this->table($v)->toLowerCase(); |
335 | 335 | }) |
336 | 336 | ->toArray(); |