Files
2026-07-15 22:42:31 +08:00

36 lines
588 B
Go

package user_repo
import (
"github.com/XingfenD/yoresee_doc/internal/model"
"gorm.io/gorm"
)
type UserListOperation struct {
repo *UserRepository
tx *gorm.DB
}
func (r *UserRepository) List() *UserListOperation {
return &UserListOperation{
repo: r,
}
}
func (op *UserListOperation) WithTx(tx *gorm.DB) *UserListOperation {
op.tx = tx
return op
}
func (op *UserListOperation) Exec() ([]model.User, error) {
var users []model.User
var err error
if op.tx != nil {
err = op.tx.Find(&users).Error
} else {
err = op.repo.db.Find(&users).Error
}
return users, err
}