Add mode, bring in definition/patch queries

This commit is contained in:
2024-06-03 21:09:03 -04:00
parent ecc13a30cf
commit 98bfceb7c9
10 changed files with 219 additions and 7 deletions

View File

@@ -24,6 +24,9 @@ class Configuration
/** @var array|null Options to use for connections (driver-specific) */
public static ?array $options = null;
/** @var Mode|null The mode in which the library is operating (filled after first connection if not configured) */
public static ?Mode $mode = null;
/**
* Retrieve a new connection to the database
*
@@ -38,8 +41,15 @@ class Configuration
$db = new PDO(self::$pdoDSN, $_ENV['PDO_DOC_USERNAME'] ?? self::$username,
$_ENV['PDO_DOC_PASSWORD'] ?? self::$password, self::$options);
// TODO: determine driver, set mode for other queries
echo $db->getAttribute(PDO::ATTR_DRIVER_NAME);
if (is_null(self::$mode)) {
$driver = $db->getAttribute(PDO::ATTR_DRIVER_NAME);
self::$mode = match ($driver) {
'pgsql' => Mode::PgSQL,
'sqlite' => Mode::SQLite,
default => throw new DocumentException(
"Unsupported driver $driver: this library currently supports PostgreSQL and SQLite")
};
}
return $db;
}
}