Documentation
¶
Overview ¶
Package ach provides bidirectional conversion between ACH files and TableData.
This package bridges the moov-io/ach library with fileparser.TableData, enabling SQL queries on ACH file data via filesql.
Security Note ¶
TableData structures expose sensitive banking information including account numbers, routing numbers, names, and transaction amounts. Avoid logging or exporting TableData contents verbatim in production environments.
Supported Addenda Types ¶
Standard entries (EntryDetail):
- Addenda02: Point-of-Sale (POS), Machine Transfer Entry (MTE), Shared Network Entry (SHR)
- Addenda05: Payment Related Information (PPD, CCD, CTX, WEB, etc.)
- Addenda98: Notification of Change (NOC)
- Addenda98Refused: Refused Notification of Change
- Addenda99: Return entries
- Addenda99Dishonored: Dishonored Returns
- Addenda99Contested: Contested Dishonored Returns
IAT entries (IATEntryDetail) - International ACH Transactions:
- Addenda10: Transaction information (receiving company, foreign payment amount)
- Addenda11: Originator name and address
- Addenda12: Originator city, state/province, country, postal code
- Addenda13: Originating DFI information
- Addenda14: Receiving DFI information
- Addenda15: Receiver identification number and street address
- Addenda16: Receiver city, state/province, country, postal code
- Addenda17: Payment related information (up to 2 per entry)
- Addenda18: Foreign correspondent bank information (up to 5 per entry)
- Addenda98/99: Same as standard entries
Limitations ¶
Only UPDATE operations on existing rows are supported for round-trip editing. INSERT/DELETE operations in SQL are not reflected in the output ACH file. This is because ACH file structure requires careful coordination between related records (entry counts, hash totals, addenda indicators).
This package uses github.com/tiendc/go-deepcopy for deep copying ACH files. If moov-io/ach adds new fields (especially interfaces or unexported fields), the deep copy may not capture them correctly. Monitor moov-io/ach releases.
Usage ¶
import (
"github.com/nao1215/fileparser/ach"
moovach "github.com/moov-io/ach"
)
// Read ACH file
achFile, _ := moovach.ReadFile("payment.ach")
// Convert to TableData for SQL queries
tables := ach.FromFile(achFile)
// After SQL modifications, convert back to ACH
newFile, _ := tables.ToFile()
Index ¶
- type TableSet
- func (ts *TableSet) GetAddendaTable() *fileparser.TableData
- func (ts *TableSet) GetBatchesTable() *fileparser.TableData
- func (ts *TableSet) GetEntriesTable() *fileparser.TableData
- func (ts *TableSet) GetFileHeaderTable() *fileparser.TableData
- func (ts *TableSet) ToFile() (*ach.File, error)
- func (ts *TableSet) UpdateAddendaFromTableData(addenda *fileparser.TableData)
- func (ts *TableSet) UpdateBatchesFromTableData(batches *fileparser.TableData)
- func (ts *TableSet) UpdateEntriesFromTableData(entries *fileparser.TableData)
- func (ts *TableSet) UpdateFileHeaderFromTableData(fileHeader *fileparser.TableData)
- func (ts *TableSet) UpdateIATAddendaFromTableData(iatAddenda *fileparser.TableData)
- func (ts *TableSet) UpdateIATBatchesFromTableData(iatBatches *fileparser.TableData)
- func (ts *TableSet) UpdateIATEntriesFromTableData(iatEntries *fileparser.TableData)
- func (ts *TableSet) WriteToWriter(writer io.Writer) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TableSet ¶
type TableSet struct {
// FileHeader contains file-level header information (1 row per file)
FileHeader *fileparser.TableData
// Batches contains batch header information
Batches *fileparser.TableData
// Entries contains entry detail records (the main transaction data)
Entries *fileparser.TableData
// Addenda contains addenda records associated with entries
Addenda *fileparser.TableData
// IATBatches contains IAT batch header information (International ACH Transactions)
IATBatches *fileparser.TableData
// IATEntries contains IAT entry detail records
IATEntries *fileparser.TableData
// IATAddenda contains IAT addenda records (types 10-18, 98, 99)
IATAddenda *fileparser.TableData
// contains filtered or unexported fields
}
TableSet contains multiple TableData representing different aspects of an ACH file. This structure preserves the hierarchical nature of ACH files while enabling flat table-based queries.
func FromFile ¶
FromFile converts an ACH file to a set of TableData structures. The returned TableSet can be used with filesql for SQL queries.
Tables created for standard batches:
- file_header: File header information (1 row)
- batches: Batch headers with control totals
- entries: Individual entry details (main transaction data)
- addenda: Addenda records linked to entries (types 02, 05, 98, 99)
Tables created for IAT (International ACH Transactions):
- iat_batches: IAT batch headers
- iat_entries: IAT entry details
- iat_addenda: IAT addenda records (types 10-18, 98, 99)
Note: The TableSet stores a reference to the original file (not a copy). If you modify the passed-in *ach.File after calling FromFile, the changes will be reflected when calling ToFile(). ToFile() creates a deep copy before applying TableData modifications.
func ParseReader ¶
ParseReader parses an ACH file from an io.Reader and returns a TableSet. This function encapsulates the moov-io/ach dependency so that callers don't need to import moov-io/ach directly.
func (*TableSet) GetAddendaTable ¶
func (ts *TableSet) GetAddendaTable() *fileparser.TableData
GetAddendaTable returns the addenda TableData for use with filesql.
func (*TableSet) GetBatchesTable ¶
func (ts *TableSet) GetBatchesTable() *fileparser.TableData
GetBatchesTable returns the batches TableData for use with filesql.
func (*TableSet) GetEntriesTable ¶
func (ts *TableSet) GetEntriesTable() *fileparser.TableData
GetEntriesTable returns the entries TableData for use with filesql. This is the most commonly used table for transaction analysis.
func (*TableSet) GetFileHeaderTable ¶
func (ts *TableSet) GetFileHeaderTable() *fileparser.TableData
GetFileHeaderTable returns the file header TableData for use with filesql.
func (*TableSet) ToFile ¶
ToFile reconstructs an ACH file from modified TableData. This allows round-trip editing: ACH -> TableData -> SQL modifications -> ACH
The function creates a deep copy of the original ACH file and applies modifications from all TableData (FileHeader, Batches, Entries, Addenda).
After modification, the file's control records are automatically recalculated.
func (*TableSet) UpdateAddendaFromTableData ¶
func (ts *TableSet) UpdateAddendaFromTableData(addenda *fileparser.TableData)
UpdateAddendaFromTableData updates the internal addenda data from modified TableData.
func (*TableSet) UpdateBatchesFromTableData ¶
func (ts *TableSet) UpdateBatchesFromTableData(batches *fileparser.TableData)
UpdateBatchesFromTableData updates the internal batches data from modified TableData.
func (*TableSet) UpdateEntriesFromTableData ¶
func (ts *TableSet) UpdateEntriesFromTableData(entries *fileparser.TableData)
UpdateEntriesFromTableData updates the internal entries data from modified TableData. Call this after making SQL modifications to prepare for ToFile().
func (*TableSet) UpdateFileHeaderFromTableData ¶
func (ts *TableSet) UpdateFileHeaderFromTableData(fileHeader *fileparser.TableData)
UpdateFileHeaderFromTableData updates the internal file header data from modified TableData.
func (*TableSet) UpdateIATAddendaFromTableData ¶
func (ts *TableSet) UpdateIATAddendaFromTableData(iatAddenda *fileparser.TableData)
UpdateIATAddendaFromTableData updates the internal IAT addenda data from modified TableData.
func (*TableSet) UpdateIATBatchesFromTableData ¶
func (ts *TableSet) UpdateIATBatchesFromTableData(iatBatches *fileparser.TableData)
UpdateIATBatchesFromTableData updates the internal IAT batches data from modified TableData.
func (*TableSet) UpdateIATEntriesFromTableData ¶
func (ts *TableSet) UpdateIATEntriesFromTableData(iatEntries *fileparser.TableData)
UpdateIATEntriesFromTableData updates the internal IAT entries data from modified TableData.