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

Function scanRow

database/balance.go:110–205  ·  view source on GitHub ↗

Scans a SQL row result and maps it into a Balance object, including optional identity and ledger data. Converts string representations of big.Int fields into actual big.Int objects.

(row *sql.Row, tx *sql.Tx, include []string)

Source from the content-addressed store, hash-verified

108// Scans a SQL row result and maps it into a Balance object, including optional identity and ledger data.
109// Converts string representations of big.Int fields into actual big.Int objects.
110func scanRow(row *sql.Row, tx *sql.Tx, include []string) (*model.Balance, error) {
111 balance := &model.Balance{}
112 identity := &model.Identity{}
113 ledger := &model.Ledger{}
114 metaDataJSON := []byte{}
115
116 // Temporary variables to hold string representations of big.Int fields
117 var balanceStr, creditBalanceStr, debitBalanceStr, inflightBalanceStr, inflightCreditBalanceStr, inflightDebitBalanceStr string
118 var indicator sql.NullString
119
120 var scanArgs []interface{}
121 // Add scan arguments for default balance fields
122 scanArgs = append(scanArgs, &balance.BalanceID, &balanceStr, &creditBalanceStr,
123 &debitBalanceStr, &balance.Currency, &balance.CurrencyMultiplier,
124 &balance.LedgerID, &balance.IdentityID, &balance.CreatedAt, &metaDataJSON,
125 &inflightBalanceStr, &inflightCreditBalanceStr, &inflightDebitBalanceStr, &balance.Version, &indicator, &balance.TrackFundLineage, &balance.AllocationStrategy)
126
127 // Conditionally scan for identity fields
128 if contains(include, "identity") {
129 scanArgs = append(scanArgs, &identity.IdentityID, &identity.FirstName, &identity.OrganizationName, &identity.Category, &identity.LastName,
130 &identity.OtherNames, &identity.Gender, &identity.DOB, &identity.EmailAddress,
131 &identity.PhoneNumber, &identity.Nationality, &identity.Street, &identity.Country,
132 &identity.State, &identity.PostCode, &identity.City, &identity.CreatedAt)
133 }
134
135 // Conditionally scan for ledger fields
136 if contains(include, "ledger") {
137 scanArgs = append(scanArgs, &ledger.LedgerID, &ledger.Name, &ledger.CreatedAt)
138 }
139
140 err := row.Scan(scanArgs...)
141 if err != nil {
142 if rollbackErr := tx.Rollback(); rollbackErr != nil {
143 return nil, fmt.Errorf("scanRow: failed to rollback transaction: %v, original error: %v", rollbackErr, err)
144 }
145 return nil, err
146 }
147
148 // Convert string representations to big.Int
149 balance.Balance, err = parseBigInt(balanceStr)
150 if err != nil {
151 _ = tx.Rollback()
152 return nil, fmt.Errorf("failed to parse balance: %w", err)
153 }
154 balance.CreditBalance, err = parseBigInt(creditBalanceStr)
155 if err != nil {
156 _ = tx.Rollback()
157 return nil, fmt.Errorf("failed to parse credit_balance: %w", err)
158 }
159 balance.DebitBalance, err = parseBigInt(debitBalanceStr)
160 if err != nil {
161 _ = tx.Rollback()
162 return nil, fmt.Errorf("failed to parse debit_balance: %w", err)
163 }
164 balance.InflightBalance, err = parseBigInt(inflightBalanceStr)
165 if err != nil {
166 _ = tx.Rollback()
167 return nil, fmt.Errorf("failed to parse inflight_balance: %w", err)

Callers 1

GetBalanceByIDMethod · 0.85

Calls 2

parseBigIntFunction · 0.85
containsFunction · 0.70

Tested by

no test coverage detected