package 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 { // AutoMigrate 创建表 AutoMigrate(tables ...Table) error // 会重置数据库连接的方法 Table(name string, args ...any) DBOperations // 会重置数据库连接的方法,一般配合Raw使用 NewSession() 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 Joins(query string, args ...any) DBOperations Where(conditions *Conditions) DBOperations Or(conditions *Conditions) DBOperations Having(conditions *Conditions) DBOperations GroupBy(groupBy string) DBOperations OrderBy(orderBy string) 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 CheckExist() (bool, error) CheckHasOnlyOne() (bool, error) }