package store import ( "context" "gorm.io/gorm" ) // Store 数据访问层基础结构 type Store struct { db *gorm.DB } // NewStore 创建新的 Store 实例 func NewStore(db *gorm.DB) *Store { return &Store{ db: db, } } // DB 获取数据库连接 func (s *Store) DB() *gorm.DB { return s.db } // Transaction 执行事务 // 提供统一的事务管理接口,自动处理提交和回滚 func (s *Store) Transaction(ctx context.Context, fn func(*gorm.DB) error) error { return s.db.WithContext(ctx).Transaction(fn) } // WithContext 返回带上下文的数据库实例 func (s *Store) WithContext(ctx context.Context) *gorm.DB { return s.db.WithContext(ctx) }