Skip to content

Commit

Permalink
refactor: add on conflict do nothing to order history insert statement
Browse files Browse the repository at this point in the history
  • Loading branch information
clD11 committed Sep 10, 2024
1 parent e66178d commit 3d5c3a0
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions services/skus/storage/repository/order_history.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,18 @@ import (

"github.com/jmoiron/sqlx"
uuid "github.com/satori/go.uuid"

"github.com/brave-intl/bat-go/services/skus/model"
)

type OrderPayHistory struct{}

func NewOrderPayHistory() *OrderPayHistory { return &OrderPayHistory{} }

func (r *OrderPayHistory) Insert(ctx context.Context, dbi sqlx.ExecerContext, id uuid.UUID, when time.Time) error {
const q = `INSERT INTO order_payment_history (order_id, last_paid) VALUES ($1, $2)`

result, err := dbi.ExecContext(ctx, q, id, when)
if err != nil {
return err
}
const q = `INSERT INTO order_payment_history (order_id, last_paid) VALUES ($1, $2) ON CONFLICT DO NOTHING`

numAffected, err := result.RowsAffected()
if err != nil {
if _, err := dbi.ExecContext(ctx, q, id, when); err != nil {
return err
}

if numAffected == 0 {
return model.ErrNoRowsChangedOrderPayHistory
}

return nil
}

0 comments on commit 3d5c3a0

Please sign in to comment.