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

Method UpdateBalanceIdentity

database/balance.go:1699–1724  ·  view source on GitHub ↗

UpdateBalanceIdentity updates the identity_id of a balance entry in the database. Parameters: - balanceID: The unique identifier of the balance whose identity reference is to be updated. - identityID: The identity ID to be associated with the balance. Returns: - error: An error is returned if the

(balanceID string, identityID string)

Source from the content-addressed store, hash-verified

1697// Returns:
1698// - error: An error is returned if the balance or identity does not exist or the database operation fails.
1699func (d Datasource) UpdateBalanceIdentity(balanceID string, identityID string) error {
1700 // Execute the SQL update statement to change the identity_id for the specified balance.
1701 result, err := d.Conn.ExecContext(context.Background(), `
1702 UPDATE ledgerforge.balances
1703 SET identity_id = $2
1704 WHERE balance_id = $1
1705 `, balanceID, identityID)
1706 // Handle SQL execution errors
1707 if err != nil {
1708 // Delegate to apierror for consistent error handling across the project
1709 return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to update balance identity", err)
1710 }
1711
1712 // Ensure a row was actually updated
1713 rowsAffected, err := result.RowsAffected()
1714 if err != nil {
1715 return apierror.NewAPIError(apierror.ErrInternalServer, "Failed to get rows affected", err)
1716 }
1717
1718 if rowsAffected == 0 {
1719 // No rows were updated – the balance record does not exist
1720 return apierror.NewAPIError(apierror.ErrNotFound, fmt.Sprintf("Balance with ID '%s' not found", balanceID), nil)
1721 }
1722
1723 return nil
1724}
1725
1726// GetAllBalancesWithFilter retrieves balances with advanced filtering support.
1727// It delegates to GetAllBalancesWithFilterAndOptions with nil options.

Calls 1

NewAPIErrorFunction · 0.92