Add support, custom, and other queries

This commit is contained in:
2024-06-03 23:10:12 -04:00
parent 98bfceb7c9
commit b705130624
13 changed files with 576 additions and 8 deletions

38
src/Definition.php Normal file
View File

@@ -0,0 +1,38 @@
<?php declare(strict_types=1);
namespace BitBadger\PDODocument;
use PDO;
/**
* Functions to create tables and indexes
*/
class Definition
{
/**
* Ensure a document table exists
*
* @param string $name The name of the table to be created if it does not exist
* @param PDO|null $pdo The database connection to use (optional; will obtain one if not provided)
* @throws DocumentException If any is encountered
*/
public static function ensureTable(string $name, ?PDO $pdo = null): void
{
Custom::nonQuery(Query\Definition::ensureTable($name), [], $pdo);
Custom::nonQuery(Query\Definition::ensureKey($name), [], $pdo);
}
/**
* Ensure a field index exists on a document table
*
* @param string $tableName The name of the table which should be indexed
* @param string $indexName The name of the index
* @param array $fields Fields which should be a part of this index
* @param PDO|null $pdo The database connection to use (optional; will obtain one if not provided)
* @throws DocumentException If any is encountered
*/
public static function ensureFieldIndex(string $tableName, string $indexName, array $fields, ?PDO $pdo = null): void
{
Custom::nonQuery(Query\Definition::ensureIndexOn($tableName, $indexName, $fields), [], $pdo);
}
}