Use new UpdateAssignmentWithDifference for ynab-import to prevent errors on duplicates

This commit is contained in:
2022-03-05 22:23:13 +00:00
parent a62ab543b0
commit 97de326527
3 changed files with 33 additions and 5 deletions

View File

@ -148,3 +148,22 @@ func (q *Queries) UpdateAssignment(ctx context.Context, arg UpdateAssignmentPara
_, err := q.db.ExecContext(ctx, updateAssignment, arg.CategoryID, arg.Date, arg.Amount)
return err
}
const updateAssignmentWithDifference = `-- name: UpdateAssignmentWithDifference :exec
INSERT INTO assignments (category_id, date, amount)
VALUES($1, $2, $3)
ON CONFLICT (category_id, date)
DO
UPDATE SET amount = assignments.amount + $3
`
type UpdateAssignmentWithDifferenceParams struct {
CategoryID uuid.UUID
Date time.Time
Amount numeric.Numeric
}
func (q *Queries) UpdateAssignmentWithDifference(ctx context.Context, arg UpdateAssignmentWithDifferenceParams) error {
_, err := q.db.ExecContext(ctx, updateAssignmentWithDifference, arg.CategoryID, arg.Date, arg.Amount)
return err
}