db_operations.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. package db_operations
  2. type DBOperations interface {
  3. BeginTransaction() TransactionDBOperations
  4. // BeginEvent() EventDBOperations
  5. BaseDBOperations
  6. }
  7. type TransactionDBOperations interface {
  8. BaseDBOperations
  9. RollbackTransaction()
  10. CommitTransaction()
  11. }
  12. type EventDBOperations interface {
  13. RollbackEvent()
  14. CommitEvent()
  15. // TODO 需要重新定义创建等方法,传递必要的key
  16. EventRows(table string, keys []string, pageSize int, pageNo string)
  17. Replay(table string, keys []string)
  18. }
  19. type BaseDBOperations interface {
  20. // 会重置数据库连接的方法
  21. Table(name string, args ...any) DBOperations
  22. // 执行SQL语句,使用Raw之后,为了触发SQL执行,需要调用Row或者Rows
  23. // 如果是查询语句,使用Rows或Row均可,主要看自己需要查询的是单行还是多行
  24. // 如果是写语句,必须使用Rows,否则由于没有返回结果,Rows会报错
  25. // 使用Raw以后,所有分页相关的参数都无效,需要使用SQL语句进行分页
  26. Raw(sql string, values ...any) DBOperations
  27. // 组织SQL语句相关的方法
  28. Select(query string, args ...any) DBOperations
  29. Where(query string, args ...any) DBOperations
  30. Or(query string, args ...any) DBOperations
  31. GroupBy(groupBy string) DBOperations
  32. OrderBy(orderBy string) DBOperations
  33. Joins(query string, args ...any) DBOperations
  34. Having(query string, args ...any) DBOperations
  35. Paging(pageNo int, pageSize int) DBOperations
  36. // 写方法
  37. Create(tableRow *TableRow) error
  38. CreateBatch(tableRows []TableRow) error
  39. Delete() error
  40. Updates(newTableRow *TableRow) error
  41. UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error)
  42. // 查询方法
  43. Rows(pageNo int, pageSize int) ([]TableRow, error)
  44. Row() (*TableRow, error)
  45. // 其他方法
  46. Count(count *int64) error
  47. CheckExist() (bool, error)
  48. CheckHasOnlyOne() (bool, error)
  49. }