pdo-document/src/Mode.php

37 lines
922 B
PHP
Raw Normal View History

<?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')
};
}
}