@@ -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 on the "one" end having "many" records in the referencing table |
| 167 | 167 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 168 | 168 | $relations = []; |
| 169 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 170 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
| 169 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 170 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
| 171 | 171 | $relation['table_name']; |
| 172 | 172 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
| 173 | 173 | $relation['column_name']; |
@@ -184,11 +184,11 @@ discard block |
||
| 184 | 184 | $usedcol = []; |
| 185 | 185 | if (count($columns)) { |
| 186 | 186 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 187 | - ->filter(function ($v) use ($columns) { |
|
| 187 | + ->filter(function($v) use ($columns) { |
|
| 188 | 188 | return in_array($v['column_name'], $columns); |
| 189 | 189 | }) as $relation |
| 190 | 190 | ) { |
| 191 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 191 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 192 | 192 | $relation['referenced_table_name']; |
| 193 | 193 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 194 | 194 | $relation['referenced_column_name']; |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | $definition->getName() == $relname || |
| 209 | 209 | $definition->getColumn($relname) |
| 210 | 210 | ) { |
| 211 | - $relname = $orig . '_' . (++ $cntr); |
|
| 211 | + $relname = $orig.'_'.(++$cntr); |
|
| 212 | 212 | } |
| 213 | 213 | $definition->addRelation( |
| 214 | 214 | new TableRelation( |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | $definition->getName() == $relname || |
| 234 | 234 | $definition->getColumn($relname) |
| 235 | 235 | ) { |
| 236 | - $relname = $orig . '_' . (++ $cntr); |
|
| 236 | + $relname = $orig.'_'.(++$cntr); |
|
| 237 | 237 | } |
| 238 | 238 | $definition->addRelation( |
| 239 | 239 | new TableRelation( |
@@ -250,8 +250,8 @@ discard block |
||
| 250 | 250 | // assuming current table is linked to "one" record in the referenced table |
| 251 | 251 | // resulting in a "belongsTo" relationship |
| 252 | 252 | $relations = []; |
| 253 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 254 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 253 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 254 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 255 | 255 | $relation['referenced_table_name']; |
| 256 | 256 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 257 | 257 | $relation['referenced_column_name']; |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | $definition->getName() == $relname || |
| 269 | 269 | $definition->getColumn($relname) |
| 270 | 270 | ) { |
| 271 | - $relname = $orig . '_' . (++ $cntr); |
|
| 271 | + $relname = $orig.'_'.(++$cntr); |
|
| 272 | 272 | } |
| 273 | 273 | $definition->addRelation( |
| 274 | 274 | new TableRelation( |
@@ -288,19 +288,19 @@ discard block |
||
| 288 | 288 | $tables = Collection::from($this |
| 289 | 289 | ->query( |
| 290 | 290 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
| 291 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
| 291 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
| 292 | 292 | )) |
| 293 | - ->mapKey(function ($v) { |
|
| 293 | + ->mapKey(function($v) { |
|
| 294 | 294 | return strtolower($v['table_name']); |
| 295 | 295 | }) |
| 296 | 296 | ->pluck('table_name') |
| 297 | - ->map(function ($v) { |
|
| 297 | + ->map(function($v) { |
|
| 298 | 298 | return $this->table($v)->toLowerCase(); |
| 299 | 299 | }) |
| 300 | 300 | ->toArray(); |
| 301 | 301 | |
| 302 | 302 | foreach (array_keys($tables) as $k) { |
| 303 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
| 303 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
| 304 | 304 | } |
| 305 | 305 | return $tables; |
| 306 | 306 | } |
@@ -32,19 +32,19 @@ discard block |
||
| 32 | 32 | $columns = Collection::from($this |
| 33 | 33 | ->query( |
| 34 | 34 | "SELECT * FROM all_tab_cols WHERE UPPER(table_name) = ? AND UPPER(owner) = ?", |
| 35 | - [ strtoupper($table), strtoupper($this->name()) ] |
|
| 35 | + [strtoupper($table), strtoupper($this->name())] |
|
| 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 all_constraints |
| 75 | 75 | WHERE table_name = ? AND constraint_type = ? AND UPPER(owner) = ?", |
| 76 | - [ strtoupper($table), 'P', $owner ] |
|
| 76 | + [strtoupper($table), 'P', $owner] |
|
| 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 all_cons_columns |
| 92 | 92 | WHERE table_name = ? AND constraint_name = ? AND UPPER(owner) = ?", |
| 93 | - [ strtoupper($table), $pkname, $owner ] |
|
| 93 | + [strtoupper($table), $pkname, $owner] |
|
| 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; |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | UPPER(ac.OWNER) = ? AND UPPER(ac.R_OWNER) = ? AND |
| 122 | 122 | ac.R_CONSTRAINT_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
| 123 | 123 | ORDER BY cc.POSITION", |
| 124 | - [ $owner, $owner, $pkname, 'R' ] |
|
| 124 | + [$owner, $owner, $pkname, 'R'] |
|
| 125 | 125 | )) |
| 126 | - ->map(function ($v) { |
|
| 126 | + ->map(function($v) { |
|
| 127 | 127 | $new = []; |
| 128 | 128 | foreach ($v as $kk => $vv) { |
| 129 | 129 | $new[strtoupper($kk)] = $vv; |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | as $relation |
| 134 | 134 | ) { |
| 135 | 135 | $relations[$relation['CONSTRAINT_NAME']]['table'] = $relation['TABLE_NAME']; |
| 136 | - $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int)$relation['POSITION']-1]] = |
|
| 136 | + $relations[$relation['CONSTRAINT_NAME']]['keymap'][$primary[(int) $relation['POSITION'] - 1]] = |
|
| 137 | 137 | $relation['COLUMN_NAME']; |
| 138 | 138 | } |
| 139 | 139 | foreach ($relations as $data) { |
@@ -164,9 +164,9 @@ discard block |
||
| 164 | 164 | ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? AND |
| 165 | 165 | cc.COLUMN_NAME IN (??) |
| 166 | 166 | ORDER BY POSITION", |
| 167 | - [ $owner, $owner, $data['table'], 'R', $columns ] |
|
| 167 | + [$owner, $owner, $data['table'], 'R', $columns] |
|
| 168 | 168 | )) |
| 169 | - ->map(function ($v) { |
|
| 169 | + ->map(function($v) { |
|
| 170 | 170 | $new = []; |
| 171 | 171 | foreach ($v as $kk => $vv) { |
| 172 | 172 | $new[strtoupper($kk)] = $vv; |
@@ -186,9 +186,9 @@ discard block |
||
| 186 | 186 | ->query( |
| 187 | 187 | "SELECT COLUMN_NAME FROM all_cons_columns |
| 188 | 188 | WHERE UPPER(OWNER) = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
| 189 | - [ $owner, current($foreign['keymap']) ] |
|
| 189 | + [$owner, current($foreign['keymap'])] |
|
| 190 | 190 | )) |
| 191 | - ->map(function ($v) { |
|
| 191 | + ->map(function($v) { |
|
| 192 | 192 | $new = []; |
| 193 | 193 | foreach ($v as $kk => $vv) { |
| 194 | 194 | $new[strtoupper($kk)] = $vv; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | $relname = $foreign['table']; |
| 204 | 204 | $cntr = 1; |
| 205 | 205 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 206 | - $relname = $foreign['table'] . '_' . (++ $cntr); |
|
| 206 | + $relname = $foreign['table'].'_'.(++$cntr); |
|
| 207 | 207 | } |
| 208 | 208 | $definition->addRelation( |
| 209 | 209 | new TableRelation( |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $relname = $data['table']; |
| 221 | 221 | $cntr = 1; |
| 222 | 222 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 223 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
| 223 | + $relname = $data['table'].'_'.(++$cntr); |
|
| 224 | 224 | } |
| 225 | 225 | $definition->addRelation( |
| 226 | 226 | new TableRelation( |
@@ -249,9 +249,9 @@ discard block |
||
| 249 | 249 | LEFT JOIN all_cons_columns cc ON cc.OWNER = ac.OWNER AND cc.CONSTRAINT_NAME = ac.CONSTRAINT_NAME |
| 250 | 250 | WHERE UPPER(ac.OWNER) = ? AND UPPER(ac.R_OWNER) = ? AND ac.TABLE_NAME = ? AND ac.CONSTRAINT_TYPE = ? |
| 251 | 251 | ORDER BY cc.POSITION", |
| 252 | - [ $owner, $owner, strtoupper($table), 'R' ] |
|
| 252 | + [$owner, $owner, strtoupper($table), 'R'] |
|
| 253 | 253 | )) |
| 254 | - ->map(function ($v) { |
|
| 254 | + ->map(function($v) { |
|
| 255 | 255 | $new = []; |
| 256 | 256 | foreach ($v as $kk => $vv) { |
| 257 | 257 | $new[strtoupper($kk)] = $vv; |
@@ -269,9 +269,9 @@ discard block |
||
| 269 | 269 | ->query( |
| 270 | 270 | "SELECT COLUMN_NAME FROM all_cons_columns |
| 271 | 271 | WHERE UPPER(OWNER) = ? AND CONSTRAINT_NAME = ? ORDER BY POSITION", |
| 272 | - [ $owner, current($data['keymap']) ] |
|
| 272 | + [$owner, current($data['keymap'])] |
|
| 273 | 273 | )) |
| 274 | - ->map(function ($v) { |
|
| 274 | + ->map(function($v) { |
|
| 275 | 275 | $new = []; |
| 276 | 276 | foreach ($v as $kk => $vv) { |
| 277 | 277 | $new[strtoupper($kk)] = $vv; |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | $relname = $data['table']; |
| 287 | 287 | $cntr = 1; |
| 288 | 288 | while ($definition->hasRelation($relname) || $definition->getName() == $relname) { |
| 289 | - $relname = $data['table'] . '_' . (++ $cntr); |
|
| 289 | + $relname = $data['table'].'_'.(++$cntr); |
|
| 290 | 290 | } |
| 291 | 291 | $definition->addRelation( |
| 292 | 292 | new TableRelation( |
@@ -310,18 +310,18 @@ discard block |
||
| 310 | 310 | SELECT VIEW_NAME AS TABLE_NAME FROM ALL_VIEWS where UPPER(OWNER) = ?", |
| 311 | 311 | [strtoupper($this->connection['name']), strtoupper($this->connection['name'])] |
| 312 | 312 | )) |
| 313 | - ->map(function ($v) { |
|
| 313 | + ->map(function($v) { |
|
| 314 | 314 | $new = []; |
| 315 | 315 | foreach ($v as $kk => $vv) { |
| 316 | 316 | $new[strtoupper($kk)] = $vv; |
| 317 | 317 | } |
| 318 | 318 | return $new; |
| 319 | 319 | }) |
| 320 | - ->mapKey(function ($v) { |
|
| 320 | + ->mapKey(function($v) { |
|
| 321 | 321 | return strtolower($v['TABLE_NAME']); |
| 322 | 322 | }) |
| 323 | 323 | ->pluck('TABLE_NAME') |
| 324 | - ->map(function ($v) { |
|
| 324 | + ->map(function($v) { |
|
| 325 | 325 | return $this->table($v)->toLowerCase(); |
| 326 | 326 | }) |
| 327 | 327 | ->toArray(); |