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

@@ -3,6 +3,8 @@
namespace BitBadger\PDODocument\Query;
use BitBadger\PDODocument\Configuration;
use BitBadger\PDODocument\DocumentException;
use BitBadger\PDODocument\Mode;
/**
* Queries to define tables and indexes
@@ -13,11 +15,16 @@ class Definition
* SQL statement to create a document table
*
* @param string $name The name of the table (including schema, if applicable)
* @param string $dataType The data type used for the document column
* @return string The CREATE TABLE statement for the document table
* @throws DocumentException If the database mode has not been set
*/
public static function ensureTableFor(string $name, string $dataType): string
public static function ensureTable(string $name): string
{
$dataType = match (Configuration::$mode) {
Mode::PgSQL => 'JSONB',
Mode::SQLite => 'TEXT',
default => throw new DocumentException('Database mode not set; cannot make create table statement')
};
return "CREATE TABLE IF NOT EXISTS $name (data $dataType NOT NULL)";
}