interface.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package 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. // 会重置数据库连接的方法,一般配合Raw使用
  23. NewSession() DBOperations
  24. // 执行SQL语句,使用Raw之后,为了触发SQL执行,需要调用Row或者Rows
  25. // 如果是查询语句,使用Rows或Row均可,主要看自己需要查询的是单行还是多行
  26. // 如果是写语句,必须使用Rows,否则由于没有返回结果,Rows会报错
  27. // 使用Raw以后,所有分页相关的参数都无效,需要使用SQL语句进行分页
  28. Raw(sql string, values ...any) DBOperations
  29. // 组织SQL语句相关的方法
  30. Select(query string, args ...any) DBOperations
  31. Joins(query string, args ...any) DBOperations
  32. Where(conditions *Conditions) DBOperations
  33. Or(conditions *Conditions) DBOperations
  34. Having(conditions *Conditions) DBOperations
  35. GroupBy(groupBy string) DBOperations
  36. OrderBy(orderBy string) DBOperations
  37. Paging(pageNo int, pageSize int) DBOperations
  38. // 写方法
  39. Create(tableRow *TableRow) error
  40. CreateBatch(tableRows []TableRow) error
  41. Delete() error
  42. Updates(newTableRow *TableRow) error
  43. UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error)
  44. // 查询方法
  45. Rows(pageNo int, pageSize int) ([]TableRow, error)
  46. Row() (*TableRow, error)
  47. // 其他方法
  48. Count(count *int64) error
  49. CheckExist() (bool, error)
  50. CheckHasOnlyOne() (bool, error)
  51. }