classUpsertMutation
final class UpsertMutation
implements DataMutation
Applies INSERT ... ON DUPLICATE KEY UPDATE (UPSERT) to the shadow store.
Type Aliases§
Row = import from TableDefinitionMethods§
public function __construct(
string $tableName,
array<int, string> $primaryKeys,
array<int, string> $updateColumns = [],
array<string, UpsertExpression|null> $updateValues = [],
CandidateKeySet|null $candidateKeys = null,
UpsertExpression|null $updatePredicate = null,
bool $databaseEvaluated = false,
array<string, string> $updateSqlValues = [],
?string $updateSqlPredicate = null,
?UpsertExpression $conflictPredicate = null,
)Parameters
$tableName | string | Target table. |
$primaryKeys | array<int, string> | Primary key columns. |
$updateColumns | array<int, string> | Columns to update on duplicate. |
$updateValues | array<string, UpsertExpression|null> | Values to use for update on duplicate. |
$candidateKeys | CandidateKeySet|null | Candidate keys used for conflict detection. |
$updatePredicate | UpsertExpression|null | Condition that controls the conflict update. |
$databaseEvaluated | bool | |
$updateSqlValues | array<string, string> | Raw expressions used only for database-evaluation diagnostics. |
$updateSqlPredicate | ?string | |
$conflictPredicate | ?UpsertExpression |
Test cases 24
UpsertMutationTest::testApplyAccumulatesExistingAndIncomingValuescoversUpsertMutationTest::testApplyAccumulatesSequentialConflictsAgainstLatestRowcoversUpsertMutationTest::testApplyHandlesMixedInsertAndUpdatecoversUpsertMutationTest::testApplyInsertsNewRowWhenNoDuplicatecoversUpsertMutationTest::testApplyUpdatesAllNonPrimaryColumnsWhenNoUpdateColumnsSpecifiedcoversUpsertMutationTest::testApplyUpdatesExistingRowOnDuplicatecoversUpsertMutationTest::testApplyUpdatesExistingRowOnUniqueKeyConflictcoversUpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscoversUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacoversUpsertMutationTest::testApplyWithCompositePrimaryKeycoversUpsertMutationTest::testApplyWithExcludedColumnReferencecoversUpsertMutationTest::testApplyWithExcludedQuotedColumnReferencecoversUpsertMutationTest::testApplyWithLiteralUpdateValuecoversUpsertMutationTest::testApplyWithMissingPrimaryKeyInsertsNewRowcoversUpsertMutationTest::testApplyWithUpdateValuesExpressioncoversUpsertMutationTest::testConflictPredicateRestrictsIncomingAndExistingCandidateRowscoversUpsertMutationTest::testDatabaseEvaluatedBatchDetectsConflictsWithRowsInsertedEarlierInStatementcoversUpsertMutationTest::testDatabaseEvaluatedBatchReevaluatesAgainstLatestConflictRowcoversUpsertMutationTest::testDatabaseEvaluatedBatchRejectsStaleUnsupportedExpressioncoversUpsertMutationTest::testDatabaseEvaluatedPredicateFallsBackWhenMetadataIsMissingcoversUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascoversUpsertMutationTest::testResultRowsAnswersNothingUntilTheStatementHasBeenAppliedcoversUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscoversUpsertMutationTest::testTableNameReturnsTableNamecovers
Calls 4
- new RowSet line 88
- static-call CandidateKeySet::fromSchema() line 95
- new ConflictSearch line 99
- new UpsertUpdate line 100
public function apply(ShadowStore $store, array $rows): void{@inheritDoc}
Parameters
$store | ShadowStore | |
$rows | array |
Throws
UnsupportedSqlException When an assignment is written in a way ZTD cannot work outTest cases 24
MutationImpactTest::testAppliedUpsertReturnsResultRowsAndIsInsertLikecallsMutationImpactTest::testSkippedConditionalUpsertHasNoAffectedOrReturningRowscallsUpsertMutationTest::testApplyAccumulatesExistingAndIncomingValuescovers and callsUpsertMutationTest::testApplyAccumulatesSequentialConflictsAgainstLatestRowcovers and callsUpsertMutationTest::testApplyHandlesMixedInsertAndUpdatecovers and callsUpsertMutationTest::testApplyInsertsNewRowWhenNoDuplicatecovers and callsUpsertMutationTest::testApplyUpdatesAllNonPrimaryColumnsWhenNoUpdateColumnsSpecifiedcovers and callsUpsertMutationTest::testApplyUpdatesExistingRowOnDuplicatecovers and callsUpsertMutationTest::testApplyUpdatesExistingRowOnUniqueKeyConflictcovers and callsUpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscovers and callsUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacovers and callsUpsertMutationTest::testApplyWithCompositePrimaryKeycovers and callsUpsertMutationTest::testApplyWithExcludedColumnReferencecovers and callsUpsertMutationTest::testApplyWithExcludedQuotedColumnReferencecovers and callsUpsertMutationTest::testApplyWithLiteralUpdateValuecovers and callsUpsertMutationTest::testApplyWithMissingPrimaryKeyInsertsNewRowcovers and callsUpsertMutationTest::testApplyWithUpdateValuesExpressioncovers and callsUpsertMutationTest::testConflictPredicateRestrictsIncomingAndExistingCandidateRowscovers and callsUpsertMutationTest::testDatabaseEvaluatedBatchDetectsConflictsWithRowsInsertedEarlierInStatementcovers and callsUpsertMutationTest::testDatabaseEvaluatedBatchReevaluatesAgainstLatestConflictRowcovers and callsUpsertMutationTest::testDatabaseEvaluatedBatchRejectsStaleUnsupportedExpressioncovers and callsUpsertMutationTest::testDatabaseEvaluatedPredicateFallsBackWhenMetadataIsMissingcovers and callsUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascovers and callsUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscovers and calls
Calls 8
- method-call ShadowStore::get() line 119
- new RowSet line 122
- method-call UpsertUpdate::incomingRow() line 124
- method-call ConflictSearch::of() line 125
- function-call
array_key_lastline 128 - method-call UpsertUpdate::applies() line 136
- method-call UpsertUpdate::of() line 140
- method-call ShadowStore::set() line 146
public function tableName(): string{@inheritDoc}
Returns
stringTest cases 1
UpsertMutationTest::testTableNameReturnsTableNamecovers and calls
public function resultRows(): list<Row>Returns
list<Row>Test cases 5
UpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscovers and callsUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacovers and callsUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascovers and callsUpsertMutationTest::testResultRowsAnswersNothingUntilTheStatementHasBeenAppliedcovers and callsUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscovers and calls
Calls 1
- function-call
array_valuesline 162
Private surface 13§
Implementation details, listed for orientation only.
private string $tableNameprivate array<int, string> $primaryKeysprivate array<int, string> $updateColumnsprivate array<string, UpsertExpression|null> $updateValuesprivate CandidateKeySet $candidateKeysprivate ?UpsertExpression $updatePredicateprivate ?UpsertExpression $conflictPredicateprivate bool $databaseEvaluatedprivate array<string, string> $updateSqlValuesprivate ?string $updateSqlPredicateprivate RowSet $resultRowsprivate ConflictSearch $conflictsprivate UpsertUpdate $updateTest cases 27§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 24
UpsertMutationTest::testApplyAccumulatesExistingAndIncomingValuescovers and callsUpsertMutationTest::testApplyAccumulatesSequentialConflictsAgainstLatestRowcovers and callsUpsertMutationTest::testApplyHandlesMixedInsertAndUpdatecovers and callsUpsertMutationTest::testApplyInsertsNewRowWhenNoDuplicatecovers and callsUpsertMutationTest::testApplyUpdatesAllNonPrimaryColumnsWhenNoUpdateColumnsSpecifiedcovers and callsUpsertMutationTest::testApplyUpdatesExistingRowOnDuplicatecovers and callsUpsertMutationTest::testApplyUpdatesExistingRowOnUniqueKeyConflictcovers and callsUpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscovers and callsUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacovers and callsUpsertMutationTest::testApplyWithCompositePrimaryKeycovers and callsUpsertMutationTest::testApplyWithExcludedColumnReferencecovers and callsUpsertMutationTest::testApplyWithExcludedQuotedColumnReferencecovers and callsUpsertMutationTest::testApplyWithLiteralUpdateValuecovers and callsUpsertMutationTest::testApplyWithMissingPrimaryKeyInsertsNewRowcovers and callsUpsertMutationTest::testApplyWithUpdateValuesExpressioncovers and callsUpsertMutationTest::testConflictPredicateRestrictsIncomingAndExistingCandidateRowscovers and callsUpsertMutationTest::testDatabaseEvaluatedBatchDetectsConflictsWithRowsInsertedEarlierInStatementcovers and callsUpsertMutationTest::testDatabaseEvaluatedBatchReevaluatesAgainstLatestConflictRowcovers and callsUpsertMutationTest::testDatabaseEvaluatedBatchRejectsStaleUnsupportedExpressioncovers and callsUpsertMutationTest::testDatabaseEvaluatedPredicateFallsBackWhenMetadataIsMissingcovers and callsUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascovers and callsUpsertMutationTest::testResultRowsAnswersNothingUntilTheStatementHasBeenAppliedcovers and callsUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscovers and callsUpsertMutationTest::testTableNameReturnsTableNamecovers and calls
Other tests reaching this symbol 3
Relations§
Type checks 3
- instanceof ZtdQuery\Shadow\Mutation\MutationImpact::affectedRowCount() packages/ztd-query-core/src/Shadow/Mutation/MutationImpact.php:60
- instanceof ZtdQuery\Shadow\Mutation\MutationImpact::returningRows() packages/ztd-query-core/src/Shadow/Mutation/MutationImpact.php:81
- instanceof ZtdQuery\Shadow\Mutation\MutationImpact::isInsertLike() packages/ztd-query-core/src/Shadow/Mutation/MutationImpact.php:106