topfans/backend/services/moderationService/service/transaction_helper.go
2026-06-22 17:19:48 +08:00

20 lines
396 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"context"
"gorm.io/gorm"
)
// TxHelper 事务封装spec §阶段 2.6
type TxHelper struct {
db *gorm.DB
}
func NewTxHelper(db *gorm.DB) *TxHelper { return &TxHelper{db: db} }
// WithTx - 业务表 + mts + reports 原子性保证
func (h *TxHelper) WithTx(ctx context.Context, fn func(*gorm.DB) error) error {
return h.db.WithContext(ctx).Transaction(fn)
}