package db_operations type DBOperations interface { BeginTransaction() TransactionDBOperations // BeginEvent() EventDBOperations BaseDBOperations } type TransactionDBOperations interface { BaseDBOperations RollbackTransaction() CommitTransaction() } type EventDBOperations interface { RollbackEvent() CommitEvent() // TODO 需要重新定义创建等方法,传递必要的key EventRows(table string, keys []string, pageSize int, pageNo string) Replay(table string, keys []string) } type BaseDBOperations interface { // 会重置数据库连接的方法 NewSession() DBOperations Table(name string, args ...any) DBOperations // 执行SQL语句,使用Raw之后,为了触发SQL执行,需要调用Row或者Rows // 如果是查询语句,使用Rows或Row均可,主要看自己需要查询的是单行还是多行 // 如果是写语句,必须使用Rows,否则由于没有返回结果,Rows会报错 // 使用Raw以后,所有分页相关的参数都无效,需要使用SQL语句进行分页 Raw(sql string, values ...any) DBOperations // 组织SQL语句相关的方法 Select(query string, args ...any) DBOperations Where(query string, args ...any) DBOperations Or(query string, args ...any) DBOperations GroupBy(groupBy string) DBOperations OrderBy(orderBy string) DBOperations Joins(query string, args ...any) DBOperations Having(query string, args ...any) DBOperations Paging(pageNo int, pageSize int) DBOperations // 写方法 Create(tableRow *TableRow) error CreateBatch(tableRows []TableRow) error Delete() error Updates(newTableRow *TableRow) error UpdatesWithRowsAffected(newTableRow *TableRow) (int64, error) // 查询方法 Rows(pageNo int, pageSize int) ([]TableRow, error) Row() (*TableRow, error) // 其他方法 Count(count *int64) error }