1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Staudenmeir\LaravelMigrationViews\Facades; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Connection; |
6
|
|
|
use Illuminate\Support\Facades\Facade; |
7
|
|
|
use RuntimeException; |
8
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Builders\MariaDbBuilder; |
9
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Builders\MySqlBuilder; |
10
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Builders\PostgresBuilder; |
11
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Builders\SQLiteBuilder; |
12
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Builders\SqlServerBuilder; |
13
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Grammars\MariaDbGrammar; |
14
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Grammars\MySqlGrammar; |
15
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Grammars\PostgresGrammar; |
16
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Grammars\SQLiteGrammar; |
17
|
|
|
use Staudenmeir\LaravelMigrationViews\Schema\Grammars\SqlServerGrammar; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @method static void createView(string $name, $query, array $columns = null, bool $orReplace = false) |
21
|
|
|
* @method static void createOrReplaceView(string $name, $query, array $columns = null) |
22
|
|
|
* @method static void createMaterializedView(string $name, $query, array $columns = null) |
23
|
|
|
* @method static void renameView(string $from, string $to) |
24
|
|
|
* @method static void dropView(string $name, bool $ifExists = false) |
25
|
|
|
* @method static void dropViewIfExists(string $name) |
26
|
|
|
* @method static array getViewColumnListing(string $name) |
27
|
|
|
* @method static void refreshMaterializedView(string $name) |
28
|
|
|
* |
29
|
|
|
* @mixin \Illuminate\Support\Facades\Schema |
30
|
|
|
*/ |
31
|
|
|
class Schema extends Facade |
32
|
|
|
{ |
33
|
|
|
/** |
34
|
|
|
* Get the registered name of the component. |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
protected static function getFacadeAccessor() |
39
|
|
|
{ |
40
|
|
|
return static::class; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Get a schema builder instance for a connection. |
45
|
|
|
* |
46
|
|
|
* @param string $name |
47
|
|
|
* @return \Illuminate\Database\Schema\Builder |
48
|
|
|
*/ |
49
|
|
|
public static function connection($name) |
50
|
|
|
{ |
51
|
|
|
return static::getSchemaBuilder( |
52
|
|
|
static::$app['db']->connection($name) |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Get the schema builder. |
58
|
|
|
* |
59
|
|
|
* @param \Illuminate\Database\Connection $connection |
60
|
|
|
* @return \Illuminate\Database\Schema\Builder |
61
|
|
|
*/ |
62
|
|
|
public static function getSchemaBuilder(Connection $connection) |
63
|
|
|
{ |
64
|
|
|
$driver = $connection->getDriverName(); |
65
|
|
|
|
66
|
|
|
switch ($driver) { |
67
|
|
|
case 'mysql': |
68
|
|
|
$connection->setSchemaGrammar($connection->withTablePrefix(new MySqlGrammar())); |
69
|
|
|
|
70
|
|
|
return new MySqlBuilder($connection); |
71
|
|
|
case 'mariadb': |
72
|
|
|
$connection->setSchemaGrammar($connection->withTablePrefix(new MariaDbGrammar())); |
73
|
|
|
|
74
|
|
|
return new MariaDbBuilder($connection); |
75
|
|
|
case 'pgsql': |
76
|
|
|
$connection->setSchemaGrammar($connection->withTablePrefix(new PostgresGrammar())); |
77
|
|
|
|
78
|
|
|
return new PostgresBuilder($connection); |
79
|
|
|
case 'sqlite': |
80
|
|
|
$connection->setSchemaGrammar($connection->withTablePrefix(new SQLiteGrammar())); |
81
|
|
|
|
82
|
|
|
return new SQLiteBuilder($connection); |
83
|
|
|
case 'sqlsrv': |
84
|
|
|
$connection->setSchemaGrammar($connection->withTablePrefix(new SqlServerGrammar())); |
85
|
|
|
|
86
|
|
|
return new SqlServerBuilder($connection); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|