Add support, custom, and other queries
This commit is contained in:
37
src/Document.php
Normal file
37
src/Document.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace BitBadger\PDODocument;
|
||||
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* Functions that apply at a whole document level
|
||||
*/
|
||||
class Document
|
||||
{
|
||||
/**
|
||||
* Insert a new document
|
||||
*
|
||||
* @param string $tableName The name of the table into which the document should be inserted
|
||||
* @param array|object $document The document to be inserted
|
||||
* @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 insert(string $tableName, array|object $document, ?PDO $pdo = null): void
|
||||
{
|
||||
Custom::nonQuery(Query::insert($tableName), Parameters::json('@data', $document), $pdo);
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a document, inserting it if it does not exist and updating it if it does (AKA "upsert")
|
||||
*
|
||||
* @param string $tableName The name of the table to which the document should be saved
|
||||
* @param array|object $document The document to be saved
|
||||
* @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 save(string $tableName, array|object $document, ?PDO $pdo = null): void
|
||||
{
|
||||
Custom::nonQuery(Query::save($tableName), Parameters::json('@data', $document), $pdo);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user