db_operations.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package db_operations
  2. type DBOperations interface {
  3. BeginTransaction() TransactionDBOperations
  4. BaseDBOperations
  5. }
  6. type TransactionDBOperations interface {
  7. BaseDBOperations
  8. RollbackTransaction()
  9. CommitTransaction()
  10. }
  11. type BaseDBOperations interface {
  12. // 会重置数据库连接的方法
  13. NewSession() DBOperations
  14. Table(name string, args ...any) DBOperations
  15. // 执行SQL语句,使用Raw之后必须使用Rows或Row,否则不执行SQL
  16. Raw(sql string, values ...any) DBOperations
  17. // 组织SQL语句相关的方法
  18. Select(query string, args ...any) DBOperations
  19. Where(query string, args ...any) DBOperations
  20. Or(query string, args ...any) DBOperations
  21. GroupBy(groupBy string) DBOperations
  22. OrderBy(orderBy string) DBOperations
  23. Joins(query string, args ...any) DBOperations
  24. Having(query string, args ...any) DBOperations
  25. Paging(pageNo int, pageSize int) DBOperations
  26. // 写方法
  27. Create(tableRow map[string]any) error
  28. CreateBatch(tableRows []map[string]any) error
  29. Delete() error
  30. Updates(updateData map[string]any) error
  31. UpdatesWithRowsAffected(updateData map[string]any) (int64, error)
  32. // 查询方法
  33. Rows(pageNo int, pageSize int) ([]map[string]any, error)
  34. Row() (map[string]any, error)
  35. // 其他方法
  36. Count(count *int64) error
  37. }