-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add upsert method and enable it for environments #2746
Conversation
if err != nil { | ||
if err == sql.ErrNoRows { | ||
created, err := m.rh.Create(r.Context(), targetResource.Spec) | ||
if err != nil { | ||
writeError(w, encoder, http.StatusInternalServerError, fmt.Errorf("cannot create entity: %w", err)) | ||
return | ||
} | ||
|
||
writeResponse(http.StatusCreated, created) | ||
return | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: we can join the two to avoid nesting:
if err != nil { | |
if err == sql.ErrNoRows { | |
created, err := m.rh.Create(r.Context(), targetResource.Spec) | |
if err != nil { | |
writeError(w, encoder, http.StatusInternalServerError, fmt.Errorf("cannot create entity: %w", err)) | |
return | |
} | |
writeResponse(http.StatusCreated, created) | |
return | |
} | |
} | |
if err != nil && err == sql.ErrNoRows { | |
created, err := m.rh.Create(r.Context(), targetResource.Spec) | |
if err != nil { | |
writeError(w, encoder, http.StatusInternalServerError, fmt.Errorf("cannot create entity: %w", err)) | |
return | |
} | |
writeResponse(http.StatusCreated, created) | |
return | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your suggestion made me realize I was ignoring the err
when it was not a sql.ErrNoRows
@@ -295,3 +295,33 @@ func (resourceClient ResourceClient) Create(ctx context.Context, file file.File) | |||
file = file.SaveChanges(IOReadCloserToString(resp.Body)) | |||
return &file, nil | |||
} | |||
|
|||
func (resourceClient ResourceClient) Upsert(ctx context.Context, file file.File) (*file.File, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that we have this out of the box now
* add upsert method and enable it for environments * handle error when getting entity
* Adding initial APIs for the example * Adding code for payment-executor-api * Adding full example * Adding trace-based tests * Updating README * Apply suggestions from code review Co-authored-by: Adnan Rahić <[email protected]> * Adding documentation to the example * fix(backend): matching trigger span duration and trigger time durations (#2740) * fix(frontend): adding default value for data store connection types (#2742) * fix(backend): fixing response status code for grpc request (#2741) * feat: add upsert method and enable it for environments (#2746) * add upsert method and enable it for environments * handle error when getting entity * PR suggestions --------- Co-authored-by: Adnan Rahić <[email protected]> Co-authored-by: Oscar Reyes <[email protected]> Co-authored-by: Matheus Nogueira <[email protected]>
* add upsert method and enable it for environments * handle error when getting entity
* Adding initial APIs for the example * Adding code for payment-executor-api * Adding full example * Adding trace-based tests * Updating README * Apply suggestions from code review Co-authored-by: Adnan Rahić <[email protected]> * Adding documentation to the example * fix(backend): matching trigger span duration and trigger time durations (#2740) * fix(frontend): adding default value for data store connection types (#2742) * fix(backend): fixing response status code for grpc request (#2741) * feat: add upsert method and enable it for environments (#2746) * add upsert method and enable it for environments * handle error when getting entity * PR suggestions --------- Co-authored-by: Adnan Rahić <[email protected]> Co-authored-by: Oscar Reyes <[email protected]> Co-authored-by: Matheus Nogueira <[email protected]>
* add upsert method and enable it for environments * handle error when getting entity
* Adding initial APIs for the example * Adding code for payment-executor-api * Adding full example * Adding trace-based tests * Updating README * Apply suggestions from code review Co-authored-by: Adnan Rahić <[email protected]> * Adding documentation to the example * fix(backend): matching trigger span duration and trigger time durations (#2740) * fix(frontend): adding default value for data store connection types (#2742) * fix(backend): fixing response status code for grpc request (#2741) * feat: add upsert method and enable it for environments (#2746) * add upsert method and enable it for environments * handle error when getting entity * PR suggestions --------- Co-authored-by: Adnan Rahić <[email protected]> Co-authored-by: Oscar Reyes <[email protected]> Co-authored-by: Matheus Nogueira <[email protected]>
This PR adds a new method for upsert the resource into the database. And enables it for transactions
Checklist