pdo-document/src/Mode.php
Daniel J. Summers d8330d828a Derive mode from DSN function
- Add headers in all files
- Minor field name changes
2024-07-20 21:47:21 -04:00

37 lines
922 B
PHP

<?php
/**
* @author Daniel J. Summers <daniel@bitbadger.solutions>
* @license MIT
*/
declare(strict_types=1);
namespace BitBadger\PDODocument;
/**
* The mode for queries generated by the library
*/
enum Mode
{
/** Storing documents in a PostgreSQL database */
case PgSQL;
/** Storing documents in a SQLite database */
case SQLite;
/**
* Derive the mode from the Data Source Name (DSN)
*
* @return Mode The database mode based on the DSN
* @throws DocumentException If the DSN does not start with `pgsql:` or `sqlite:`
*/
public static function deriveFromDSN(string $dsn): Mode
{
return match (true) {
str_starts_with($dsn, 'pgsql:') => Mode::PgSQL,
str_starts_with($dsn, 'sqlite:') => Mode::SQLite,
default => throw new DocumentException('This library currently supports PostgreSQL and SQLite')
};
}
}