Add mode, bring in definition/patch queries
This commit is contained in:
@@ -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)";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user