-
Notifications
You must be signed in to change notification settings - Fork 20
/
Builder.php
61 lines (50 loc) · 1.77 KB
/
Builder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
declare(strict_types=1);
namespace Umbrellio\Postgres\Schema;
use Closure;
use Illuminate\Database\Schema\PostgresBuilder as BasePostgresBuilder;
use Illuminate\Support\Traits\Macroable;
class Builder extends BasePostgresBuilder
{
use Macroable;
public $name;
public function createView(string $view, string $select, $materialize = false): void
{
$blueprint = $this->createBlueprint($view);
$blueprint->createView($view, $select, $materialize);
$this->build($blueprint);
}
public function dropView(string $view): void
{
$blueprint = $this->createBlueprint($view);
$blueprint->dropView($view);
$this->build($blueprint);
}
public function hasView(string $view): bool
{
return count($this->connection->selectFromWriteConnection($this->grammar->compileViewExists(), [
$this->connection->getConfig()['schema'],
$this->connection->getTablePrefix() . $view,
])) > 0;
}
public function getForeignKeys(string $tableName): array
{
return $this->connection->selectFromWriteConnection($this->grammar->compileForeignKeysListing($tableName));
}
public function getViewDefinition($view): string
{
$results = $this->connection->selectFromWriteConnection($this->grammar->compileViewDefinition(), [
$this->connection->getConfig()['schema'],
$this->connection->getTablePrefix() . $view,
]);
return count($results) > 0 ? $results[0]->view_definition : '';
}
/**
* @param string $table
* @return Blueprint|\Illuminate\Database\Schema\Blueprint
*/
protected function createBlueprint($table, Closure $callback = null)
{
return new Blueprint($table, $callback);
}
}