updates
This commit is contained in:
21
server/internal/models/base.go
Normal file
21
server/internal/models/base.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type BaseModel struct {
|
||||
ID ULID `gorm:"primaryKey" json:"id" db:"id" `
|
||||
CreatedAt time.Time `json:"createdAt" db:"created_at"`
|
||||
UpdatedAt time.Time `json:"updatedAt" db:"updated_at"`
|
||||
}
|
||||
|
||||
// BeforeCreate is a GORM hook that runs before creating a record
|
||||
func (b *BaseModel) BeforeCreate(tx *gorm.DB) error {
|
||||
if b.ID.IsZero() {
|
||||
b.ID = GenerateULID()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user