diff --git a/db/db.go b/db/db.go index 2ec76a9..e535d14 100644 --- a/db/db.go +++ b/db/db.go @@ -20,24 +20,25 @@ type HoTimeDB struct { ContextBase DBName string *cache.HoTimeCache - Log *logrus.Logger - Type string // 数据库类型: mysql, sqlite3, postgres - Prefix string - LastQuery string - LastData []interface{} - ConnectFunc func(err ...*Error) (*sql.DB, *sql.DB) - LastErr *Error - limit Slice - *sql.Tx //事务对象 - SlaveDB *sql.DB // 从数据库 - Mode int // mode为0生产模式,1为测试模式,2为开发模式 - mu sync.RWMutex - limitMu sync.Mutex - Dialect Dialect // 数据库方言适配器 - testTx *sql.Tx // 测试事务:设置后所有操作都在此事务内,测试结束回滚 - testMu *sync.Mutex // 保护 testTx 单连接不被并发访问 + Log *logrus.Logger + Type string // 数据库类型: mysql, sqlite3, postgres + Prefix string + LastQuery string + LastData []interface{} + ConnectFunc func(err ...*Error) (*sql.DB, *sql.DB) + LastErr *Error + limit Slice + *sql.Tx //事务对象 + SlaveDB *sql.DB // 从数据库 + Mode int // mode为0生产模式,1为测试模式,2为开发模式 + mu sync.RWMutex + limitMu sync.Mutex + Dialect Dialect // 数据库方言适配器 + testTx *sql.Tx // 测试事务:设置后所有操作都在此事务内,测试结束回滚 + testMu *sync.Mutex // 保护 testTx 单连接不被并发访问 testLogBuf *bytes.Buffer // 测试模式:SQL 日志写入此 buffer 而非直接打印,失败时才输出 testLogBufMu sync.Mutex // 保护 testLogBuf 并发写入 + txFailed *bool // 事务内是否有SQL出错,出错则事务必须回滚(指针确保按值传递 HoTimeDB 时状态共享) } // SetConnect 设置数据库配置连接