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 a schema builder instance for the default connection. |
43
|
|
|
* |
44
|
|
|
* @return \Illuminate\Database\Schema\Builder |
45
|
|
|
*/ |
46
|
44 |
|
protected static function getFacadeAccessor() |
47
|
|
|
{ |
48
|
44 |
|
return static::getSchemaBuilder( |
49
|
44 |
|
static::$app['db']->connection() |
50
|
|
|
); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Get the schema builder. |
55
|
|
|
* |
56
|
|
|
* @param \Illuminate\Database\Connection $connection |
57
|
|
|
* @return \Illuminate\Database\Schema\Builder |
58
|
|
|
*/ |
59
|
44 |
|
protected static function getSchemaBuilder(Connection $connection) |
60
|
|
|
{ |
61
|
44 |
|
$driver = $connection->getDriverName(); |
62
|
|
|
|
63
|
44 |
|
switch ($driver) { |
64
|
44 |
|
case 'mysql': |
65
|
11 |
|
$connection->setSchemaGrammar($connection->withTablePrefix(new MySqlGrammar)); |
66
|
|
|
|
67
|
11 |
|
return new MySqlBuilder($connection); |
68
|
33 |
|
case 'pgsql': |
69
|
11 |
|
$connection->setSchemaGrammar($connection->withTablePrefix(new PostgresGrammar)); |
70
|
|
|
|
71
|
11 |
|
return new PostgresBuilder($connection); |
72
|
22 |
|
case 'sqlite': |
73
|
11 |
|
$connection->setSchemaGrammar($connection->withTablePrefix(new SQLiteGrammar)); |
74
|
|
|
|
75
|
11 |
|
return new SQLiteBuilder($connection); |
76
|
11 |
|
case 'sqlsrv': |
77
|
11 |
|
$connection->setSchemaGrammar($connection->withTablePrefix(new SqlServerGrammar)); |
78
|
|
|
|
79
|
11 |
|
return new SqlServerBuilder($connection); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
throw new RuntimeException('This database is not supported.'); // @codeCoverageIgnore |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|