Skip to content

Commit 23968ef

Browse files
authored
Allow delete to execute via DML statement (#49)
1 parent a9b956b commit 23968ef

File tree

1 file changed

+8
-24
lines changed

1 file changed

+8
-24
lines changed

spanner/spanner.go

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -564,18 +564,10 @@ func ignoreInsert(iter *spanner.RowIterator) (bool, error) {
564564

565565
func (sc *SpannerClient) DeleteUsingMutations(ctx context.Context, query responsehandler.QueryMetadata) (*message.RowsResult, string, error) {
566566
otelgo.AddAnnotation(ctx, DeleteUsingMutations)
567-
568-
var err error
569-
if sc.ReplayProtection {
570-
_, err = sc.Client.Apply(ctx,
571-
[]*spanner.Mutation{buildDeleteMutation(&query)},
572-
spanner.ApplyCommitOptions(sc.BuildCommitOptions()))
573-
} else {
574-
_, err = sc.Client.Apply(ctx,
575-
[]*spanner.Mutation{buildDeleteMutation(&query)},
576-
spanner.ApplyAtLeastOnce(),
577-
spanner.ApplyCommitOptions(sc.BuildCommitOptions()))
578-
}
567+
_, err := sc.Client.Apply(ctx,
568+
[]*spanner.Mutation{buildDeleteMutation(&query)},
569+
spanner.ApplyAtLeastOnce(),
570+
spanner.ApplyCommitOptions(sc.BuildCommitOptions()))
579571
if err != nil {
580572
sc.Logger.Error("Error while Mutation Delete - "+query.Query, zap.Error(err))
581573
return nil, CommitAPI, err
@@ -800,11 +792,7 @@ func (sc *SpannerClient) prepareQueriesAsBatch(ctx context.Context, txn *spanner
800792
ms = append(ms, buildInsertOrUpdateMutation(query))
801793
}
802794
case deleteType:
803-
if filteredResponse.CanExecuteAsMutations && len(query.MutationKeyRange) > 0 {
804-
ms = append(ms, buildDeleteMutation(query))
805-
} else {
806-
stmts = append(stmts, *buildStmt(query))
807-
}
795+
stmts = append(stmts, *buildStmt(query))
808796
case updateType:
809797
stmt, err := sc.prepareStatement(ctx, txn, query)
810798
if err != nil {
@@ -845,13 +833,9 @@ func (sc *SpannerClient) executeQueriesInSequence(ctx context.Context, txn *span
845833
ms = append(ms, buildInsertOrUpdateMutation(query))
846834
}
847835
case deleteType:
848-
if len(query.MutationKeyRange) > 0 {
849-
ms = append(ms, buildDeleteMutation(query))
850-
} else {
851-
_, err := txn.Update(ctx, *buildStmt(query))
852-
if err != nil {
853-
return fmt.Errorf("failed to execute batch update: %w", err)
854-
}
836+
_, err := txn.Update(ctx, *buildStmt(query))
837+
if err != nil {
838+
return fmt.Errorf("failed to execute batch update: %w", err)
855839
}
856840
case updateType:
857841
stmt, err := sc.prepareStatement(ctx, txn, query)

0 commit comments

Comments
 (0)