MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / RecordMatchingRule

Method RecordMatchingRule

database/reconciliation.go:414–436  ·  view source on GitHub ↗

RecordMatchingRule saves a new matching rule to the database. Parameters: - ctx: Context for managing the request and tracing. - rule: A pointer to the MatchingRule object containing rule details. Returns: - An error wrapped in an APIError if the operation fails.

(ctx context.Context, rule *model.MatchingRule)

Source from the content-addressed store, hash-verified

412// Returns:
413// - An error wrapped in an APIError if the operation fails.
414func (d Datasource) RecordMatchingRule(ctx context.Context, rule *model.MatchingRule) error {
415 ctx, span := otel.Tracer("reconciliation.database").Start(ctx, "Saving matching rule to db")
416 defer span.End()
417
418 // Marshal the matching rule criteria into JSON format
419 criteriaJSON, err := json.Marshal(rule.Criteria)
420 if err != nil {
421 return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to marshal matching rule criteria", err)
422 }
423
424 // Execute the SQL insert query to record the rule in the database
425 _, err = d.Conn.ExecContext(ctx,
426 `INSERT INTO ledgerforge.matching_rules(
427 rule_id, created_at, updated_at, name, description, criteria
428 ) VALUES ($1, $2, $3, $4, $5, $6)`,
429 rule.RuleID, rule.CreatedAt, rule.UpdatedAt, rule.Name, rule.Description, criteriaJSON,
430 )
431 if err != nil {
432 return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to record matching rule", err)
433 }
434
435 return nil
436}
437
438// GetMatchingRules retrieves all matching rules from the database.
439// Parameters:

Callers 2

Calls 2

NewAPIErrorFunction · 0.92
StartMethod · 0.45

Tested by 2