recordMatchInTransaction inserts a match into the database within a transaction context. It is used to save matches during a reconciliation process, ensuring atomicity in batch operations. Parameters: - ctx: Context for managing request and tracing. - tx: The current database transaction in which th
(ctx context.Context, tx *sql.Tx, match *model.Match)
| 255 | // Returns: |
| 256 | // - An error if the operation fails, wrapped in an APIError for consistency. |
| 257 | func (d Datasource) recordMatchInTransaction(ctx context.Context, tx *sql.Tx, match *model.Match) error { |
| 258 | _, err := tx.ExecContext(ctx, |
| 259 | `INSERT INTO ledgerforge.matches( |
| 260 | external_transaction_id, internal_transaction_id, reconciliation_id, amount, date |
| 261 | ) VALUES ($1, $2, $3, $4, $5)`, |
| 262 | match.ExternalTransactionID, match.InternalTransactionID, match.ReconciliationID, match.Amount, match.Date, |
| 263 | ) |
| 264 | if err != nil { |
| 265 | // For other errors, return the original error |
| 266 | return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to record match", err) |
| 267 | } |
| 268 | |
| 269 | return nil |
| 270 | } |
| 271 | |
| 272 | // RecordMatch inserts a single match into the database. |
| 273 | // It is used to record the match between external and internal transactions during reconciliation. |
no test coverage detected