From 0372f86cd207ea3868b9ea30e19b60720aea6eca Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Sat, 2 Nov 2024 13:55:15 +0000 Subject: [PATCH] Use DB_CONNECTION string instead of SQLITE_DB_NAME --- .env.example | 2 +- src/dependencies.php | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.env.example b/.env.example index 160958a..2d4188b 100644 --- a/.env.example +++ b/.env.example @@ -1 +1 @@ -SQLITE_DB_NAME=app.db \ No newline at end of file +DB_CONNECTION=sqlite3://app.db \ No newline at end of file diff --git a/src/dependencies.php b/src/dependencies.php index 060de1a..6386c09 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -2,6 +2,7 @@ use DI\Container; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Tools\DsnParser; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManager; use Doctrine\ORM\ORMSetup; @@ -48,10 +49,10 @@ $container->set(EntityManager::class, static function() { isDevMode: true, ); - $connection = DriverManager::getConnection([ - 'driver' => 'pdo_sqlite', - 'path' => __DIR__ . '/../' . $_ENV["SQLITE_DB_NAME"], - ], $config); + $dsnParser = new DsnParser(); + $params = $dsnParser->parse($_ENV["DB_CONNECTION"]); + + $connection = DriverManager::getConnection($params, $config); $connection->executeQuery("PRAGMA foreign_keys = ON");