1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Staudenmeir\LaravelMigrationViews\Schema\Builders; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Schema\SqlServerBuilder as Base; |
6
|
|
|
|
7
|
|
|
class SqlServerBuilder extends Base |
8
|
|
|
{ |
9
|
|
|
use ManagesViews { |
10
|
|
|
createView as createViewParent; |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Create a new view on the schema. |
15
|
|
|
* |
16
|
|
|
* @param string $name |
17
|
|
|
* @param \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|string $query |
18
|
|
|
* @param array|null $columns |
19
|
|
|
* @param bool $orReplace |
20
|
|
|
* @return void |
21
|
|
|
*/ |
22
|
10 |
|
public function createView($name, $query, array $columns = null, $orReplace = false) |
23
|
|
|
{ |
24
|
10 |
|
if ($orReplace) { |
25
|
1 |
|
$this->dropViewIfExists($name); |
26
|
|
|
} |
27
|
|
|
|
28
|
10 |
|
$this->createViewParent($name, $query, $columns); |
29
|
10 |
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Drop a view from the schema. |
33
|
|
|
* |
34
|
|
|
* @param string $name |
35
|
|
|
* @param bool $ifExists |
36
|
|
|
* @return void |
37
|
|
|
*/ |
38
|
11 |
|
public function dropView($name, $ifExists = false) |
39
|
|
|
{ |
40
|
11 |
|
$this->connection->statement( |
41
|
11 |
|
$this->grammar->compileDropView($name, $ifExists), |
42
|
11 |
|
$ifExists ? [$this->connection->getTablePrefix().$name] : [] |
43
|
|
|
); |
44
|
11 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Get the bindings for a "Has View" statement. |
48
|
|
|
* |
49
|
|
|
* @param string $view |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
3 |
|
protected function getBindingsForHasView($view) |
53
|
|
|
{ |
54
|
3 |
|
return [$view]; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get the column listing for a given view. |
59
|
|
|
* |
60
|
|
|
* @param string $name |
61
|
|
|
* @return array |
62
|
|
|
*/ |
63
|
1 |
|
public function getViewColumnListing($name) |
64
|
|
|
{ |
65
|
1 |
|
$results = $this->connection->selectFromWriteConnection( |
66
|
1 |
|
$this->grammar->compileViewColumnListing(), |
67
|
1 |
|
[$this->connection->getTablePrefix().$name] |
68
|
|
|
); |
69
|
|
|
|
70
|
1 |
|
return $this->connection->getPostProcessor()->processColumnListing($results); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|