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 |
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::testApplyAccumulatesExistingAndIncomingValuescallsUpsertMutationTest::testApplyAccumulatesSequentialConflictsAgainstLatestRowcallsUpsertMutationTest::testApplyHandlesMixedInsertAndUpdatecallsUpsertMutationTest::testApplyInsertsNewRowWhenNoDuplicatecallsUpsertMutationTest::testApplyUpdatesAllNonPrimaryColumnsWhenNoUpdateColumnsSpecifiedcallsUpsertMutationTest::testApplyUpdatesExistingRowOnDuplicatecallsUpsertMutationTest::testApplyUpdatesExistingRowOnUniqueKeyConflictcallsUpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscallsUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacallsUpsertMutationTest::testApplyWithCompositePrimaryKeycallsUpsertMutationTest::testApplyWithExcludedColumnReferencecallsUpsertMutationTest::testApplyWithExcludedQuotedColumnReferencecallsUpsertMutationTest::testApplyWithLiteralUpdateValuecallsUpsertMutationTest::testApplyWithMissingPrimaryKeyInsertsNewRowcallsUpsertMutationTest::testApplyWithUpdateValuesExpressioncallsUpsertMutationTest::testConflictPredicateRestrictsIncomingAndExistingCandidateRowscallsUpsertMutationTest::testDatabaseEvaluatedBatchDetectsConflictsWithRowsInsertedEarlierInStatementcallsUpsertMutationTest::testDatabaseEvaluatedBatchReevaluatesAgainstLatestConflictRowcallsUpsertMutationTest::testDatabaseEvaluatedBatchRejectsStaleUnsupportedExpressioncallsUpsertMutationTest::testDatabaseEvaluatedPredicateFallsBackWhenMetadataIsMissingcallsUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascallsUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscalls
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(): stringpublic function resultRows(): list<Row>Returns
list<Row>Test cases 5
UpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscallsUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacallsUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascallsUpsertMutationTest::testResultRowsAnswersNothingUntilTheStatementHasBeenAppliedcallsUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscalls
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 62§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 24
UpsertMutationTest::testApplyAccumulatesExistingAndIncomingValuescallsUpsertMutationTest::testApplyAccumulatesSequentialConflictsAgainstLatestRowcallsUpsertMutationTest::testApplyHandlesMixedInsertAndUpdatecallsUpsertMutationTest::testApplyInsertsNewRowWhenNoDuplicatecallsUpsertMutationTest::testApplyUpdatesAllNonPrimaryColumnsWhenNoUpdateColumnsSpecifiedcallsUpsertMutationTest::testApplyUpdatesExistingRowOnDuplicatecallsUpsertMutationTest::testApplyUpdatesExistingRowOnUniqueKeyConflictcallsUpsertMutationTest::testApplyUsesConflictPredicateAndReportsOnlyAppliedRowscallsUpsertMutationTest::testApplyUsesDatabaseEvaluatedValuesAndStripsMetadatacallsUpsertMutationTest::testApplyWithCompositePrimaryKeycallsUpsertMutationTest::testApplyWithExcludedColumnReferencecallsUpsertMutationTest::testApplyWithExcludedQuotedColumnReferencecallsUpsertMutationTest::testApplyWithLiteralUpdateValuecallsUpsertMutationTest::testApplyWithMissingPrimaryKeyInsertsNewRowcallsUpsertMutationTest::testApplyWithUpdateValuesExpressioncallsUpsertMutationTest::testConflictPredicateRestrictsIncomingAndExistingCandidateRowscallsUpsertMutationTest::testDatabaseEvaluatedBatchDetectsConflictsWithRowsInsertedEarlierInStatementcallsUpsertMutationTest::testDatabaseEvaluatedBatchReevaluatesAgainstLatestConflictRowcallsUpsertMutationTest::testDatabaseEvaluatedBatchRejectsStaleUnsupportedExpressioncallsUpsertMutationTest::testDatabaseEvaluatedPredicateFallsBackWhenMetadataIsMissingcallsUpsertMutationTest::testResultRowsAnswersEveryRowTheStatementWroteOrLeftAsItWascallsUpsertMutationTest::testResultRowsAnswersNothingUntilTheStatementHasBeenAppliedcallsUpsertMutationTest::testSkippedConditionalRowDoesNotStopFollowingRowscallsUpsertMutationTest::testTableNameReturnsTableNamecalls
Other tests reaching this symbol 38
SqliteRewriterTest::testInsertOnConflictReturnsUpsertMutationcallsDataMutationTest::providerRowChangingMutationcallsMutationImpactTest::testAppliedUpsertReturnsResultRowsAndIsInsertLikecallsMutationImpactTest::testSkippedConditionalUpsertHasNoAffectedOrReturningRowscallsMySqlMutationResolverTest::testInsertOnDuplicateKeyUpdateReturnsUpsertcallsMySqlMutationResolverTest::testInsertOnDuplicateKeyUpdateWithQualifiedColumncallsMySqlMutationResolverTest::testResolveInsertOnDuplicateKeyExtractsQualifiedColumnNamecallsMySqlMutationResolverTest::testResolveInsertOnDuplicateKeyExtractsUpdateColumnscallsMySqlMutationResolverTest::testResolveInsertOnDuplicateKeyReturnsUpsertMutationcallsMySqlMutationResolverTest::testResolveInsertOnDuplicateKeyWithBacktickedColumncallsMySqlMutationResolverTest::testResolveInsertOnDuplicateKeyWithDottedColumncallsMySqlMutationResolverTest::testResolveInsertOnDuplicateKeyWithoutRegisteredSchemacallsMySqlMutationResolverTest::testResolveInsertWithOnDuplicateKeyReturnsUpsertMutationcallsMySqlMutationResolverTest::testResolveInsertWithQualifiedOnDuplicateKeycallsMySqlMutationResolverTest::testResolveRowAliasUpsertAppliesIncomingColumnscallsMySqlMutationResolverTest::testResolveUpsertReturnsPrimaryKeysFromDefinitioncallsPgSqlMutationResolverTest::testResolveInsertWithOnConflictDoUpdatecallsPgSqlMutationResolverTest::testResolveInsertWithOnConflictDoUpdateReturnsUpsertMutationcallsPgSqlMutationResolverTest::testResolveOnConflictDoUpdateWithoutRegisteredSchemacallsPgSqlMutationResolverTest::testResolveUpsertConflictValuesArePreservedcallsPgSqlMutationResolverTest::testResolveUpsertConflictValuesMappingcallsPgSqlMutationResolverTest::testResolveUpsertConflictValuesPreservedcallsPgSqlMutationResolverTest::testResolveUpsertReturnsPrimaryKeysAndConflictColumnscallsPgSqlMutationResolverTest::testResolveUpsertTernaryRegisteredTableUsesDefinitionPrimaryKeyscallsPgSqlMutationResolverTest::testResolveUpsertUsesPartialIndexPredicateForConflictDetectioncallsPgSqlMutationResolverTest::testResolveUpsertValuesFromConflictClausecallsPgSqlMutationResolverTest::testResolveUpsertWithMultipleSetColumnscallsPgSqlMutationResolverTest::testResolveUpsertWithRegisteredTableUsesRegistrycallsInsertMutationResolverTest::testResolveInsertUpsertcallsInsertMutationResolverTest::testResolveInsertUpsertTableNameAndUpdateColumnscallsInsertMutationResolverTest::testResolveInsertUpsertWithDefinitionPrimaryKeyscallsInsertMutationResolverTest::testResolveInsertUpsertWithDefinitionReturnsPrimaryKeyscallsInsertMutationResolverTest::testResolveInsertUpsertWithoutDefinitionReturnsEmptyPrimaryKeyscallsSqliteMutationResolverTest::testResolveUpsertcallsSqliteMutationResolverTest::testResolveUpsertTableNameAndUpdateColumnscallsSqliteMutationResolverTest::testResolveUpsertWithDefinitionPrimaryKeyscallsSqliteMutationResolverTest::testResolveUpsertWithDefinitionReturnsPrimaryKeyscallsSqliteMutationResolverTest::testResolveUpsertWithoutDefinitionReturnsEmptyPrimaryKeyscalls
Relations§
Instantiated in 3
- new ZtdQuery\Platform\MySql\Shadow\Mutation\Row\RowMutationResolver::resolveInsert() packages/ztd-query-mysql/src/Shadow/Mutation/Row/RowMutationResolver.php:189
- new ZtdQuery\Platform\Postgres\Shadow\Mutation\Row\RowMutationResolver::resolveUpsert() packages/ztd-query-postgres/src/Shadow/Mutation/Row/RowMutationResolver.php:207
- new ZtdQuery\Platform\Sqlite\Shadow\Resolution\InsertMutationResolver::resolveOnConflict() packages/ztd-query-sqlite/src/Shadow/Resolution/InsertMutationResolver.php:93
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