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