protected function saveCreateDelete(string $type, Entity $entity): int
    {
        if (! $this->store->inTransaction()) {
            $this->store->beginTransaction();
        }

        // Create a new query
        $query      = $this->entityManager
            ->getQueryBuilder()
            ->table($this->table)
            ->{$type}();
        $idField    = $entity::getIdField();
        $properties = $entity->forDataStore();

        /* @var QueryBuilder $query */

        // If this is an insert
        if ($type === 'insert') {
            // Ensure all the required properties are set
            $this->ensureRequiredProperties($entity, $properties);
        }

        // If this type isn't an insert
        if ($type !== 'insert') {
            // Set the id for the where clause
            $query->where($idField . ' = ' . $this->criterionParam($idField));
        }

        if ($type !== 'delete') {
            // Set the properties
            $this->setPropertiesForSaveCreateDeleteQuery($query, $properties);
        }

        // Prepare a PDO statement with the query
        $stmt = $this->store->prepare($query->getQuery());

        // If this type isn't an insert
        if ($type !== 'insert') {
            // Set the id value for the where clause
            $stmt->bindValue($this->criterionParam($idField), $properties[$idField]);
        }

        if ($type !== 'delete') {
            // Set the properties.
            $this->setPropertiesForSaveCreateDeleteStatement($stmt, $properties);
        }

        // If the execute failed
        if (! $executeResult = $stmt->execute()) {
            // Throw a fail exception
            throw new ExecuteException($stmt->errorInfo()[2]);
        }

        return $executeResult;
    }
protected function saveCreateDelete(string $type, Entity $entity): int
    {
        if (! $this->store->inTransaction()) {
            $this->store->beginTransaction();
        }

        // Create a new query
        $query      = $this->entityManager
            ->getQueryBuilder()
            ->table($this->table)
            ->{$type}();
        $idField    = $entity::getIdField();
        $properties = $entity->forDataStore();

        /* @var QueryBuilder $query */

        // If this is an insert
        if ($type === 'insert') {
            // Ensure all the required properties are set
            $this->ensureRequiredProperties($entity, $properties);
        }

        // If this type isn't an insert
        if ($type !== 'insert') {
            // Set the id for the where clause
            $query->where($idField . ' = ' . $this->criterionParam($idField));
        }

        if ($type !== 'delete') {
            // Set the properties
            $this->setPropertiesForSaveCreateDeleteQuery($query, $properties);
        }

        // Prepare a PDO statement with the query
        $stmt = $this->store->prepare($query->getQuery());

        // If this type isn't an insert
        if ($type !== 'insert') {
            // Set the id value for the where clause
            $stmt->bindValue($this->criterionParam($idField), $properties[$idField]);
        }

        if ($type !== 'delete') {
            // Set the properties.
            $this->setPropertiesForSaveCreateDeleteStatement($stmt, $properties);
        }

        // If the execute failed
        if (! $executeResult = $stmt->execute()) {
            // Throw a fail exception
            throw new ExecuteException($stmt->errorInfo()[2]);
        }

        return $executeResult;
    }
protected function saveCreateDelete ( string $ type , Entity $ entity ) : int { if ( ! $ this -> store -> inTransaction ( ) ) { $ this -> store -> beginTransaction ( ) ; } // Create a new query $ query = $ this -> entityManager -> getQueryBuilder ( ) -> table ( $ this -> table ) -> { $ type } ( ) ; $ idField = $ entity :: getIdField ( ) ; $ properties = $ entity -> forDataStore ( ) ; /* @var QueryBuilder $query */ // If this is an insert if ( $ type === 'insert' ) { // Ensure all the required properties are set $ this -> ensureRequiredProperties ( $ entity , $ properties ) ; } // If this type isn't an insert if ( $ type !== 'insert' ) { // Set the id for the where clause $ query -> where ( $ idField . ' = ' . $ this -> criterionParam ( $ idField ) ) ; } if ( $ type !== 'delete' ) { // Set the properties $ this -> setPropertiesForSaveCreateDeleteQuery ( $ query , $ properties ) ; } // Prepare a PDO statement with the query $ stmt = $ this -> store -> prepare ( $ query -> getQuery ( ) ) ; // If this type isn't an insert if ( $ type !== 'insert' ) { // Set the id value for the where clause $ stmt -> bindValue ( $ this -> criterionParam ( $ idField ) , $ properties [ $ idField ] ) ; } if ( $ type !== 'delete' ) { // Set the properties. $ this -> setPropertiesForSaveCreateDeleteStatement ( $ stmt , $ properties ) ; } // If the execute failed if ( ! $ executeResult = $ stmt -> execute ( ) ) { // Throw a fail exception throw new ExecuteException ( $ stmt -> errorInfo ( ) [ 2 ] ) ; } return $ executeResult ; }
Save or create or delete a row.

<code>
$this
->saveOrCreate(
'update' | 'insert' | 'delete',
Entity::class
)
</code>

@param string $type
@param Entity $entity

@throws ExecuteException
@throws InvalidArgumentException

@return int
Save or create or delete a row .