table_row.go 929 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package sql
  2. // TableRow 数据库表行
  3. type TableRow struct {
  4. columns []string
  5. values []any
  6. err error
  7. }
  8. // NewTableRow 创建数据库表行
  9. func NewTableRow() *TableRow {
  10. return &TableRow{
  11. columns: make([]string, 0),
  12. values: make([]any, 0),
  13. }
  14. }
  15. // Add 添加表行
  16. // 参数:
  17. // - column: 列名
  18. // - value: 列值
  19. // 返回值:
  20. // - 数据库表行
  21. func (tableRow *TableRow) Add(column string, value any) *TableRow {
  22. if tableRow.err != nil {
  23. return tableRow
  24. }
  25. tableRow.columns = append(tableRow.columns, "\""+column+"\"")
  26. tableRow.values = append(tableRow.values, value)
  27. return tableRow
  28. }
  29. // Columns 获取添加的列名
  30. // 参数: 无
  31. // 返回值:
  32. // - 添加的列名
  33. func (tableRow *TableRow) Columns() []string {
  34. return tableRow.columns
  35. }
  36. // Values 获取添加的列值
  37. // 参数: 无
  38. // 返回值:
  39. // - 添加的列值
  40. func (tableRow *TableRow) Values() []any {
  41. return tableRow.values
  42. }