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