table_row.go 556 B

123456789101112131415161718192021222324252627282930313233343536
  1. package sql_tpl
  2. type TableRows struct {
  3. Rows []TableRow
  4. err error
  5. }
  6. type TableRow struct {
  7. Column string
  8. Value string
  9. }
  10. func NewTableRows() *TableRows {
  11. return &TableRows{
  12. Rows: make([]TableRow, 0),
  13. }
  14. }
  15. func (tableRows *TableRows) Add(column string, value any) *TableRows {
  16. if tableRows.err != nil {
  17. return tableRows
  18. }
  19. parsedValue, err := parseValue(value)
  20. if err != nil {
  21. tableRows.err = err
  22. return tableRows
  23. }
  24. tableRows.Rows = append(tableRows.Rows, TableRow{
  25. Column: column,
  26. Value: parsedValue,
  27. })
  28. return tableRows
  29. }