DeployHelper/internal/service/sys_sequence_service.go

32 lines
645 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 (
"ego/internal/conf"
"strings"
"sync"
)
type SysSequenceService struct {
mutex sync.Mutex
tableName string
}
// SysSequenceServiceBuilder 创建一个SysSequenceService
func SysSequenceServiceBuilder(tableName string) *SysSequenceService {
return &SysSequenceService{
tableName: tableName,
}
}
// GenerateId 根据表名生成ID使用序列
func (s *SysSequenceService) GenerateId() (string, error) {
s.mutex.Lock()
defer s.mutex.Unlock()
var id string
err := conf.Db.Raw("SELECT NEXTVAL(?)", strings.ToLower(s.tableName)).Scan(&id).Error
if err != nil {
return "", err
}
return id, nil
}