DeleteMatchingRule deletes a specific matching rule from the database. Parameters: - ctx: Context for managing the request and tracing. - id: The ID of the matching rule to be deleted. Returns: - An error wrapped in an APIError if the operation fails, or nil if the deletion is successful.
(ctx context.Context, id string)
| 533 | // Returns: |
| 534 | // - An error wrapped in an APIError if the operation fails, or nil if the deletion is successful. |
| 535 | func (d Datasource) DeleteMatchingRule(ctx context.Context, id string) error { |
| 536 | ctx, span := otel.Tracer("reconciliation.database").Start(ctx, "Deleting matching rule") |
| 537 | defer span.End() |
| 538 | |
| 539 | // Execute the SQL delete statement |
| 540 | result, err := d.Conn.ExecContext(ctx, ` |
| 541 | DELETE FROM ledgerforge.matching_rules |
| 542 | WHERE rule_id = $1 |
| 543 | `, id) |
| 544 | if err != nil { |
| 545 | return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to delete matching rule", err) |
| 546 | } |
| 547 | |
| 548 | // Check how many rows were affected |
| 549 | rowsAffected, err := result.RowsAffected() |
| 550 | if err != nil { |
| 551 | return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to get rows affected", err) |
| 552 | } |
| 553 | |
| 554 | // If no rows were affected, return a NotFound error |
| 555 | if rowsAffected == 0 { |
| 556 | return apierror.NewAPIError(apierror.ErrNotFound, fmt.Sprintf("Matching rule with ID '%s' not found", id), nil) |
| 557 | } |
| 558 | |
| 559 | return nil |
| 560 | } |
| 561 | |
| 562 | // GetMatchingRule retrieves a specific matching rule from the database by its rule ID. |
| 563 | // Parameters: |