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