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