1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Umbrellio\Postgres\Schema; |
||
6 | |||
7 | use Closure; |
||
8 | use Illuminate\Database\Schema\PostgresBuilder as BasePostgresBuilder; |
||
9 | use Illuminate\Support\Traits\Macroable; |
||
10 | |||
11 | class Builder extends BasePostgresBuilder |
||
12 | { |
||
13 | use Macroable; |
||
14 | |||
15 | public $name; |
||
16 | |||
17 | /** |
||
18 | * @codeCoverageIgnore |
||
19 | */ |
||
20 | public function createView(string $view, string $select, $materialize = false): void |
||
21 | { |
||
22 | $blueprint = $this->createBlueprint($view); |
||
23 | $blueprint->createView($view, $select, $materialize); |
||
24 | $this->build($blueprint); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @codeCoverageIgnore |
||
29 | */ |
||
30 | public function dropView(string $view): void |
||
31 | { |
||
32 | $blueprint = $this->createBlueprint($view); |
||
33 | $blueprint->dropView($view); |
||
34 | $this->build($blueprint); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @codeCoverageIgnore |
||
39 | */ |
||
40 | public function hasView($view): bool |
||
41 | { |
||
42 | return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [ |
||
43 | $this->connection->getConfig()['schema'], |
||
44 | $this->connection->getTablePrefix() . $view, |
||
45 | ])) > 0; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * @codeCoverageIgnore |
||
50 | */ |
||
51 | public function getForeignKeys($tableName): array |
||
52 | { |
||
53 | return $this->connection->selectFromWriteConnection($this->grammar->compileForeignKeysListing($tableName)); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @codeCoverageIgnore |
||
58 | */ |
||
59 | public function getViewDefinition($view): string |
||
60 | { |
||
61 | $results = $this->connection->selectFromWriteConnection($this->grammar->compileViewDefinition(), [ |
||
62 | $this->connection->getConfig()['schema'], |
||
63 | $this->connection->getTablePrefix() . $view, |
||
64 | ]); |
||
65 | return count($results) > 0 ? $results[0]->view_definition : ''; |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @param string $table |
||
70 | * @return Blueprint|\Illuminate\Database\Schema\Blueprint |
||
71 | */ |
||
72 | 27 | protected function createBlueprint($table, Closure $callback = null) |
|
73 | { |
||
74 | 27 | return new Blueprint($this->connection, $table, $callback); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
75 | } |
||
76 | } |
||
77 |