2024-07-21 01:47:21 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Daniel J. Summers <daniel@bitbadger.solutions>
|
|
|
|
* @license MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2024-06-08 23:58:45 +00:00
|
|
|
|
|
|
|
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;
|
2024-07-21 01:47:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2024-07-22 02:02:16 +00:00
|
|
|
default => throw new DocumentException('This library currently supports PostgreSQL and SQLite'),
|
2024-07-21 01:47:21 +00:00
|
|
|
};
|
|
|
|
}
|
2024-06-08 23:58:45 +00:00
|
|
|
}
|