@@ -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,18 +53,18 @@ 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 | } |
61 | 61 | |
62 | 62 | $columns = Collection::from($this |
63 | 63 | ->query("PRAGMA table_info(".$table.")")) |
64 | - ->mapKey(function ($v) { |
|
64 | + ->mapKey(function($v) { |
|
65 | 65 | return $v['name']; |
66 | 66 | }) |
67 | - ->map(function ($v) { |
|
67 | + ->map(function($v) { |
|
68 | 68 | $v['length'] = null; |
69 | 69 | if (!isset($v['type'])) { |
70 | 70 | return $v; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | default: |
75 | 75 | if (strpos($type, 'char') !== false && strpos($type, '(') !== false) { |
76 | 76 | // extract length from varchar |
77 | - $v['length'] = (int)explode(')', explode('(', $type)[1])[0]; |
|
77 | + $v['length'] = (int) explode(')', explode('(', $type)[1])[0]; |
|
78 | 78 | $v['length'] = $v['length'] > 0 ? $v['length'] : null; |
79 | 79 | } |
80 | 80 | break; |
@@ -83,15 +83,15 @@ discard block |
||
83 | 83 | }) |
84 | 84 | ->toArray(); |
85 | 85 | if (!count($columns)) { |
86 | - throw new DBException('Table not found by name: ' . implode('.', [$schema,$table])); |
|
86 | + throw new DBException('Table not found by name: '.implode('.', [$schema, $table])); |
|
87 | 87 | } |
88 | 88 | $primary = []; |
89 | 89 | foreach ($columns as $column) { |
90 | - if ((int)$column['pk']) { |
|
90 | + if ((int) $column['pk']) { |
|
91 | 91 | $primary[] = $column['name']; |
92 | 92 | } |
93 | 93 | } |
94 | - $tables[$schema . '.' .$table] = $definition = (new Table($table, $schema)) |
|
94 | + $tables[$schema.'.'.$table] = $definition = (new Table($table, $schema)) |
|
95 | 95 | ->addColumns($columns) |
96 | 96 | ->setPrimaryKey($primary) |
97 | 97 | ->setComment(''); |
@@ -101,8 +101,8 @@ discard block |
||
101 | 101 | // assuming current table is on the "one" end having "many" records in the referencing table |
102 | 102 | // resulting in a "hasMany" or "manyToMany" relationship (if a pivot table is detected) |
103 | 103 | $relations = []; |
104 | - foreach ($relationsR[$schema . '.' . $table] ?? [] as $k => $relation) { |
|
105 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['table']; |
|
104 | + foreach ($relationsR[$schema.'.'.$table] ?? [] as $k => $relation) { |
|
105 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['table']; |
|
106 | 106 | $relations[$relation['constraint_name']]['keymap'][$relation['to']] = $relation['from']; |
107 | 107 | } |
108 | 108 | foreach ($relations as $data) { |
@@ -117,11 +117,11 @@ discard block |
||
117 | 117 | $usedcol = []; |
118 | 118 | if (count($columns)) { |
119 | 119 | foreach (Collection::from($relationsT[$data['table']] ?? []) |
120 | - ->filter(function ($v) use ($columns) { |
|
120 | + ->filter(function($v) use ($columns) { |
|
121 | 121 | return in_array($v['from'], $columns); |
122 | 122 | }) as $relation |
123 | 123 | ) { |
124 | - $foreign[$relation['constraint_name']]['table'] = 'main.' . |
|
124 | + $foreign[$relation['constraint_name']]['table'] = 'main.'. |
|
125 | 125 | $relation['referenced_table']; |
126 | 126 | $foreign[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
127 | 127 | $usedcol[] = $relation['from']; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | $definition->getName() == $relname || |
141 | 141 | $definition->getColumn($relname) |
142 | 142 | ) { |
143 | - $relname = $orig . '_' . (++ $cntr); |
|
143 | + $relname = $orig.'_'.(++$cntr); |
|
144 | 144 | } |
145 | 145 | $definition->addRelation( |
146 | 146 | new TableRelation( |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | $definition->getName() == $relname || |
165 | 165 | $definition->getColumn($relname) |
166 | 166 | ) { |
167 | - $relname = $orig . '_' . (++ $cntr); |
|
167 | + $relname = $orig.'_'.(++$cntr); |
|
168 | 168 | } |
169 | 169 | $definition->addRelation( |
170 | 170 | new TableRelation( |
@@ -180,8 +180,8 @@ discard block |
||
180 | 180 | // assuming current table is linked to "one" record in the referenced table |
181 | 181 | // resulting in a "belongsTo" relationship |
182 | 182 | $relations = []; |
183 | - foreach ($relationsT[$schema . '.' . $table] ?? [] as $relation) { |
|
184 | - $relations[$relation['constraint_name']]['table'] = 'main.' . $relation['referenced_table']; |
|
183 | + foreach ($relationsT[$schema.'.'.$table] ?? [] as $relation) { |
|
184 | + $relations[$relation['constraint_name']]['table'] = 'main.'.$relation['referenced_table']; |
|
185 | 185 | $relations[$relation['constraint_name']]['keymap'][$relation['from']] = $relation['to']; |
186 | 186 | } |
187 | 187 | foreach ($relations as $name => $data) { |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $definition->getName() == $relname || |
197 | 197 | $definition->getColumn($relname) |
198 | 198 | ) { |
199 | - $relname = $orig . '_' . (++ $cntr); |
|
199 | + $relname = $orig.'_'.(++$cntr); |
|
200 | 200 | } |
201 | 201 | $definition->addRelation( |
202 | 202 | new TableRelation( |
@@ -217,9 +217,9 @@ discard block |
||
217 | 217 | "SELECT tbl_name |
218 | 218 | FROM sqlite_schema |
219 | 219 | WHERE (type = ? OR type = ?) AND tbl_name NOT LIKE 'sqlite_%';", |
220 | - [ 'table', 'view' ] |
|
220 | + ['table', 'view'] |
|
221 | 221 | )) |
222 | - ->mapKey(function ($v) { |
|
222 | + ->mapKey(function($v) { |
|
223 | 223 | return strtolower($v['tbl_name']); |
224 | 224 | }) |
225 | 225 | ->pluck('tbl_name') |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | $tables[$k] = $this->table($v, true, array_keys($tables))->toLowerCase(); |
229 | 229 | } |
230 | 230 | foreach (array_keys($tables) as $k) { |
231 | - $tables[($this->connection['opts']['schema'] ?? 'main') . '.' . $k] = &$tables[$k]; |
|
231 | + $tables[($this->connection['opts']['schema'] ?? 'main').'.'.$k] = &$tables[$k]; |
|
232 | 232 | } |
233 | 233 | return $tables; |
234 | 234 | } |