alpha2 (#2)
- Change multiple field matching to enum - Implement auto-generated IDs Reviewed-on: #2
This commit was merged in pull request #2.
This commit is contained in:
@@ -16,7 +16,25 @@ class Document
|
||||
*/
|
||||
public static function insert(string $tableName, array|object $document): void
|
||||
{
|
||||
Custom::nonQuery(Query::insert($tableName), Parameters::json(':data', $document));
|
||||
$doInsert = fn() => Custom::nonQuery(Query::insert($tableName), Parameters::json(':data', $document));
|
||||
|
||||
if (Configuration::$autoId == AutoId::None) {
|
||||
$doInsert();
|
||||
return;
|
||||
}
|
||||
|
||||
$id = Configuration::$idField;
|
||||
$idProvided =
|
||||
(is_array( $document) && is_int( $document[$id]) && $document[$id] <> 0)
|
||||
|| (is_array( $document) && is_string($document[$id]) && $document[$id] <> '')
|
||||
|| (is_object($document) && is_int( $document->{$id}) && $document->{$id} <> 0)
|
||||
|| (is_object($document) && is_string($document->{$id}) && $document->{$id} <> '');
|
||||
|
||||
if ($idProvided) {
|
||||
$doInsert();
|
||||
} else {
|
||||
Custom::nonQuery(Query::insert($tableName, Configuration::$autoId), Parameters::json(':data', $document));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user