Files
nginx-ui/model/model.go
Jacky 9225c96250 feat/dns (#1466)
* feat: dns management

* refactor(dns): streamline domain management functions and enhance validation

* feat(dns): add value suggestions for DNS record input with autocomplete functionality

* fix(dns): handle edge case in record listing pagination

* fix(dns): update credential property name for consistency and add cleanup on component unmount

* feat(dns): implement DDNS management #1194, #1140
2025-12-08 17:45:30 +08:00

87 lines
1.7 KiB
Go

package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gen"
"gorm.io/gorm"
)
var db *gorm.DB
type Model struct {
ID uint64 `gorm:"primary_key" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt *gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty"`
}
// BaseModelUUID defines a base model with UUID as the primary key.
type BaseModelUUID struct {
ID uuid.UUID `gorm:"type:uuid;primary_key;" json:"id"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// BeforeCreate will set a UUID rather than numeric ID.
func (base *BaseModelUUID) BeforeCreate(tx *gorm.DB) (err error) {
if base.ID == uuid.Nil {
base.ID = uuid.New()
}
return
}
func GenerateAllModel() []any {
return []any{
ConfigBackup{},
User{},
AuthToken{},
Cert{},
LLMSession{},
Site{},
Stream{},
DnsCredential{},
DnsDomain{},
Node{},
Notification{},
AcmeUser{},
BanIP{},
Config{},
Passkey{},
Namespace{},
ExternalNotify{},
AutoBackup{},
SiteConfig{},
NginxLogIndex{},
UpstreamConfig{},
}
}
func Use(tx *gorm.DB) {
db = tx
}
func UseDB() *gorm.DB {
return db
}
type Pagination struct {
Total int64 `json:"total"`
PerPage int `json:"per_page"`
CurrentPage int `json:"current_page"`
TotalPages int64 `json:"total_pages"`
}
type DataList struct {
Data interface{} `json:"data"`
Pagination Pagination `json:"pagination,omitempty"`
}
type Method interface {
// FirstByID Where("id=@id")
FirstByID(id uint64) (*gen.T, error)
// DeleteByID update @@table set deleted_at=strftime('%Y-%m-%d %H:%M:%S','now') where id=@id
DeleteByID(id uint64) error
}