refactor: susun semula struktur folder — Laravel source ke src/
This commit is contained in:
32
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/DatabaseSchemaDriver.php
vendored
Normal file
32
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/DatabaseSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
abstract class DatabaseSchemaDriver
|
||||
{
|
||||
public function __construct(protected ?string $connection = null)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
protected function hasTable(?string $table): bool
|
||||
{
|
||||
return $table !== null && $table !== '';
|
||||
}
|
||||
|
||||
abstract public function getViews(): array;
|
||||
|
||||
abstract public function getStoredProcedures(): array;
|
||||
|
||||
abstract public function getFunctions(): array;
|
||||
|
||||
abstract public function getTriggers(?string $table = null): array;
|
||||
|
||||
abstract public function getCheckConstraints(string $table): array;
|
||||
|
||||
abstract public function getSequences(): array;
|
||||
|
||||
abstract public function getTables(): array;
|
||||
}
|
||||
89
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/MySQLSchemaDriver.php
vendored
Normal file
89
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/MySQLSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class MySQLSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT TABLE_NAME as name, VIEW_DEFINITION as definition
|
||||
FROM information_schema.VIEWS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('SHOW PROCEDURE STATUS WHERE Db = DATABASE()');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('SHOW FUNCTION STATUS WHERE Db = DATABASE()');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
try {
|
||||
if ($this->hasTable($table)) {
|
||||
return DB::connection($this->connection)->select('SHOW TRIGGERS WHERE `Table` = ?', [$table]);
|
||||
}
|
||||
|
||||
return DB::connection($this->connection)->select('SHOW TRIGGERS');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT CONSTRAINT_NAME, CHECK_CLAUSE
|
||||
FROM information_schema.CHECK_CONSTRAINTS
|
||||
WHERE CONSTRAINT_SCHEMA = DATABASE()
|
||||
AND TABLE_NAME = ?
|
||||
', [$table]);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT TABLE_NAME as name
|
||||
FROM information_schema.TABLES
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND TABLE_TYPE = "BASE TABLE"
|
||||
ORDER BY TABLE_NAME
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
43
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/NullSchemaDriver.php
vendored
Normal file
43
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/NullSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
class NullSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
116
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/PostgreSQLSchemaDriver.php
vendored
Normal file
116
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/PostgreSQLSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PostgreSQLSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT schemaname, viewname, definition
|
||||
FROM pg_views
|
||||
WHERE schemaname NOT IN ('pg_catalog', 'information_schema')
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT proname, prosrc, proargnames, prorettype
|
||||
FROM pg_proc p
|
||||
JOIN pg_namespace n ON p.pronamespace = n.oid
|
||||
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
AND prokind = 'p'
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT proname, prosrc, proargnames, prorettype
|
||||
FROM pg_proc p
|
||||
JOIN pg_namespace n ON p.pronamespace = n.oid
|
||||
WHERE n.nspname NOT IN ('pg_catalog', 'information_schema')
|
||||
AND prokind = 'f'
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
try {
|
||||
$sql = '
|
||||
SELECT trigger_name, event_manipulation, event_object_table, action_statement
|
||||
FROM information_schema.triggers
|
||||
WHERE trigger_schema = current_schema()
|
||||
';
|
||||
|
||||
if ($this->hasTable($table)) {
|
||||
$sql .= ' AND event_object_table = ?';
|
||||
|
||||
return DB::connection($this->connection)->select($sql, [$table]);
|
||||
}
|
||||
|
||||
return DB::connection($this->connection)->select($sql);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT conname, pg_get_constraintdef(oid) as definition
|
||||
FROM pg_constraint
|
||||
WHERE contype = 'c'
|
||||
AND conrelid = ?::regclass
|
||||
", [$table]);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT sequence_name, start_value, minimum_value, maximum_value, increment
|
||||
FROM information_schema.sequences
|
||||
WHERE sequence_schema = current_schema()
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select('
|
||||
SELECT tablename as name
|
||||
FROM pg_tables
|
||||
WHERE schemaname = current_schema()
|
||||
ORDER BY tablename
|
||||
');
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
76
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SQLiteSchemaDriver.php
vendored
Normal file
76
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SQLiteSchemaDriver.php
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SQLiteSchemaDriver extends DatabaseSchemaDriver
|
||||
{
|
||||
public function getViews(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT name, sql
|
||||
FROM sqlite_master
|
||||
WHERE type = 'view'
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getStoredProcedures(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getFunctions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTriggers(?string $table = null): array
|
||||
{
|
||||
try {
|
||||
$sql = "SELECT name, sql FROM sqlite_master WHERE type = 'trigger'";
|
||||
|
||||
if ($this->hasTable($table)) {
|
||||
$sql .= ' AND tbl_name = ?';
|
||||
|
||||
return DB::connection($this->connection)->select($sql, [$table]);
|
||||
}
|
||||
|
||||
return DB::connection($this->connection)->select($sql);
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
public function getCheckConstraints(string $table): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getSequences(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function getTables(): array
|
||||
{
|
||||
try {
|
||||
return DB::connection($this->connection)->select("
|
||||
SELECT name
|
||||
FROM sqlite_master
|
||||
WHERE type = 'table'
|
||||
AND name NOT LIKE 'sqlite_%'
|
||||
ORDER BY name
|
||||
");
|
||||
} catch (Exception) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
27
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SchemaDriverFactory.php
vendored
Normal file
27
vendor/laravel/boost/src/Mcp/Tools/DatabaseSchema/SchemaDriverFactory.php
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laravel\Boost\Mcp\Tools\DatabaseSchema;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SchemaDriverFactory
|
||||
{
|
||||
public static function make(?string $connection = null): DatabaseSchemaDriver
|
||||
{
|
||||
$connectionName = $connection ?? config('database.default');
|
||||
$driverName = config("database.connections.{$connectionName}.driver");
|
||||
|
||||
if (! is_string($driverName) || $driverName === '') {
|
||||
$driverName = DB::connection($connectionName)->getDriverName();
|
||||
}
|
||||
|
||||
return match ($driverName) {
|
||||
'mysql', 'mariadb' => new MySQLSchemaDriver($connection),
|
||||
'pgsql' => new PostgreSQLSchemaDriver($connection),
|
||||
'sqlite' => new SQLiteSchemaDriver($connection),
|
||||
default => new NullSchemaDriver($connection),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user