diff --git a/backend/app/Services/DatabaseService.php b/backend/app/Services/DatabaseService.php new file mode 100644 index 0000000..3ab2f88 --- /dev/null +++ b/backend/app/Services/DatabaseService.php @@ -0,0 +1,77 @@ +driver = $driver; + return $this; + } + + /** + * Get the current driver. + * + * @throws \Exception + */ + public function getDriver(): DatabaseDriverInterface + { + if (!$this->driver) { + throw new \Exception("Database driver not initialized."); + } + return $this->driver; + } + + /** + * Establish a connection. + */ + public function connect(array $config): bool + { + return $this->getDriver()->connect($config); + } + + /** + * Get all databases. + */ + public function getDatabases(): array + { + $driver = $this->getDriver(); + if ($driver instanceof SchemaDiscoveryInterface) { + return $driver->getDatabases(); + } + throw new \Exception("Driver does not support schema discovery."); + } + + /** + * Get all tables. + */ + public function getTables(): array + { + $driver = $this->getDriver(); + if ($driver instanceof SchemaDiscoveryInterface) { + return $driver->getTables(); + } + throw new \Exception("Driver does not support schema discovery."); + } + + /** + * Get table schema. + */ + public function getTableSchema(string $table): array + { + $driver = $this->getDriver(); + if ($driver instanceof SchemaDiscoveryInterface) { + return $driver->getTableSchema($table); + } + throw new \Exception("Driver does not support schema discovery."); + } +}