@@ -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,15 +114,15 @@ 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 | - ->filter(function ($v) { |
|
| 119 | + ->filter(function($v) { |
|
| 120 | 120 | return $v['is_identity'] === 'YES' || $v['is_generated'] !== 'ALWAYS'; |
| 121 | 121 | }) |
| 122 | - ->mapKey(function ($v): string { |
|
| 122 | + ->mapKey(function($v): string { |
|
| 123 | 123 | return $v['column_name']; |
| 124 | 124 | }) |
| 125 | - ->map(function ($v) { |
|
| 125 | + ->map(function($v) { |
|
| 126 | 126 | $v['length'] = null; |
| 127 | 127 | if (!isset($v['data_type'])) { |
| 128 | 128 | return $v; |
@@ -130,20 +130,20 @@ discard block |
||
| 130 | 130 | switch ($v['data_type']) { |
| 131 | 131 | case 'character': |
| 132 | 132 | case 'character varying': |
| 133 | - $v['length'] = (int)$v['character_maximum_length']; |
|
| 133 | + $v['length'] = (int) $v['character_maximum_length']; |
|
| 134 | 134 | break; |
| 135 | 135 | } |
| 136 | 136 | return $v; |
| 137 | 137 | }) |
| 138 | 138 | ->toArray(); |
| 139 | 139 | if (!count($columns)) { |
| 140 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
| 140 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
| 141 | 141 | } |
| 142 | 142 | $pkname = Collection::from($this |
| 143 | 143 | ->query( |
| 144 | 144 | "SELECT constraint_name FROM information_schema.table_constraints |
| 145 | 145 | WHERE table_name = ? AND constraint_type = ? AND table_schema = ? AND table_catalog = ?", |
| 146 | - [ $table, 'PRIMARY KEY', $schema, $catalog ] |
|
| 146 | + [$table, 'PRIMARY KEY', $schema, $catalog] |
|
| 147 | 147 | )) |
| 148 | 148 | ->pluck('constraint_name') |
| 149 | 149 | ->value(); |
@@ -153,12 +153,12 @@ discard block |
||
| 153 | 153 | ->query( |
| 154 | 154 | "SELECT column_name FROM information_schema.constraint_column_usage |
| 155 | 155 | WHERE table_name = ? AND constraint_name = ? AND table_schema = ? AND table_catalog = ?", |
| 156 | - [ $table, $pkname, $schema, $catalog ] |
|
| 156 | + [$table, $pkname, $schema, $catalog] |
|
| 157 | 157 | )) |
| 158 | 158 | ->pluck('column_name') |
| 159 | 159 | ->toArray(); |
| 160 | 160 | } |
| 161 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
| 161 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
| 162 | 162 | ->addColumns($columns) |
| 163 | 163 | ->setPrimaryKey($primary) |
| 164 | 164 | ->setComment(''); |
@@ -168,8 +168,8 @@ discard block |
||
| 168 | 168 | // assuming current table is on the "one" end having "many" records in the referencing table |
| 169 | 169 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
| 170 | 170 | $relations = []; |
| 171 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $relation) { |
|
| 172 | - $relations[$relation['constraint_name']]['table'] = $relation['table_schema'] . '.' . |
|
| 171 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $relation) { |
|
| 172 | + $relations[$relation['constraint_name']]['table'] = $relation['table_schema'].'.'. |
|
| 173 | 173 | $relation['table_name']; |
| 174 | 174 | $relations[$relation['constraint_name']]['keymap'][$relation['referenced_column_name']] = |
| 175 | 175 | $relation['column_name']; |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | $usedcol = []; |
| 187 | 187 | if (count($columns)) { |
| 188 | 188 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
| 189 | - ->filter(function ($v) use ($columns) { |
|
| 189 | + ->filter(function($v) use ($columns) { |
|
| 190 | 190 | return in_array($v['column_name'], $columns); |
| 191 | 191 | }) as $relation |
| 192 | 192 | ) { |
| 193 | - $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 193 | + $foreign[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 194 | 194 | $relation['referenced_table_name']; |
| 195 | 195 | $foreign[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 196 | 196 | $relation['referenced_column_name']; |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $definition->getName() == $relname || |
| 211 | 211 | $definition->getColumn($relname) |
| 212 | 212 | ) { |
| 213 | - $relname = $orig . '_' . (++ $cntr); |
|
| 213 | + $relname = $orig.'_'.(++$cntr); |
|
| 214 | 214 | } |
| 215 | 215 | $definition->addRelation( |
| 216 | 216 | new TableRelation( |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | $definition->getName() == $relname || |
| 236 | 236 | $definition->getColumn($relname) |
| 237 | 237 | ) { |
| 238 | - $relname = $orig . '_' . (++ $cntr); |
|
| 238 | + $relname = $orig.'_'.(++$cntr); |
|
| 239 | 239 | } |
| 240 | 240 | $definition->addRelation( |
| 241 | 241 | new TableRelation( |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | // assuming current table is linked to "one" record in the referenced table |
| 253 | 253 | // resulting in a "belongsTo" relationship |
| 254 | 254 | $relations = []; |
| 255 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
| 256 | - $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'] . '.' . |
|
| 255 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
| 256 | + $relations[$relation['constraint_name']]['table'] = $relation['referenced_table_schema'].'.'. |
|
| 257 | 257 | $relation['referenced_table_name']; |
| 258 | 258 | $relations[$relation['constraint_name']]['keymap'][$relation['column_name']] = |
| 259 | 259 | $relation['referenced_column_name']; |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $definition->getName() == $relname || |
| 271 | 271 | $definition->getColumn($relname) |
| 272 | 272 | ) { |
| 273 | - $relname = $orig . '_' . (++ $cntr); |
|
| 273 | + $relname = $orig.'_'.(++$cntr); |
|
| 274 | 274 | } |
| 275 | 275 | $definition->addRelation( |
| 276 | 276 | new TableRelation( |
@@ -290,19 +290,19 @@ discard block |
||
| 290 | 290 | $tables = Collection::from($this |
| 291 | 291 | ->query( |
| 292 | 292 | "SELECT table_name FROM information_schema.tables where table_schema = ? AND table_catalog = ?", |
| 293 | - [ $this->connection['opts']['schema'] ?? 'public', $this->connection['name'] ] |
|
| 293 | + [$this->connection['opts']['schema'] ?? 'public', $this->connection['name']] |
|
| 294 | 294 | )) |
| 295 | - ->mapKey(function ($v) { |
|
| 295 | + ->mapKey(function($v) { |
|
| 296 | 296 | return strtolower($v['table_name']); |
| 297 | 297 | }) |
| 298 | 298 | ->pluck('table_name') |
| 299 | - ->map(function ($v) { |
|
| 299 | + ->map(function($v) { |
|
| 300 | 300 | return $this->table($v)->toLowerCase(); |
| 301 | 301 | }) |
| 302 | 302 | ->toArray(); |
| 303 | 303 | |
| 304 | 304 | foreach (array_keys($tables) as $k) { |
| 305 | - $tables[($this->connection['opts']['schema'] ?? 'public') . '.' . $k] = &$tables[$k]; |
|
| 305 | + $tables[($this->connection['opts']['schema'] ?? 'public').'.'.$k] = &$tables[$k]; |
|
| 306 | 306 | } |
| 307 | 307 | return $tables; |
| 308 | 308 | } |