package db_operations type DBOperations interface { BeginTransaction() TransactionDBOperations BaseDBOperations } type TransactionDBOperations interface { BaseDBOperations RollbackTransaction() CommitTransaction() } type BaseDBOperations interface { // 会重置数据库连接的方法 NewSession() DBOperations Table(name string, args ...any) DBOperations 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(model interface{}) error Delete(idModel interface{}) error Updates(idModel interface{}, updateData map[string]any) error UpdatesWithRowsAffected(idModel interface{}, updateData map[string]any) (int64, error) // 使用Model的查询方法 Query(models interface{}, pageNo int, pageSize int) error QueryOne(model interface{}) error // 不使用Model的查询方法,需要结合Table或者Raw使用,如需分页,需要配合Paging Row() (map[string]any, error) Rows() ([]map[string]any, error) // 其他方法 Count(count *int64) error }