* @license MIT */ declare(strict_types=1); namespace BitBadger\PDODocument; /** * 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 * @throws DocumentException If any is encountered */ public static function ensureTable(string $name): void { Custom::nonQuery(Query\Definition::ensureTable($name), []); Custom::nonQuery(Query\Definition::ensureKey($name), []); } /** * 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 string[] $fields Fields which should be a part of this index * @throws DocumentException If any is encountered */ public static function ensureFieldIndex(string $tableName, string $indexName, array $fields): void { Custom::nonQuery(Query\Definition::ensureIndexOn($tableName, $indexName, $fields), []); } /** * Create a full-document index on a table (PostgreSQL only) * * @param string $tableName The name of the table on which the document index should be created * @param DocumentIndex $indexType The type of document index to create * @throws DocumentException If the database mode is not PostgreSQL or if an error occurs creating the index */ public static function ensureDocumentIndex(string $tableName, DocumentIndex $indexType): void { Custom::nonQuery(Query\Definition::ensureDocumentIndexOn($tableName, $indexType), []); } }