This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
otter-space-sdk/pkg/models/pgModels/orm.go
2024-06-04 23:14:02 +02:00

26 lines
393 B
Go

package pgModels
import (
gonanoid "github.com/matoous/go-nanoid/v2"
"gorm.io/gorm"
"time"
)
type BaseModel struct {
ID string `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
func (base *BaseModel) BeforeCreate(db *gorm.DB) error {
id, err := gonanoid.New()
if err != nil {
return err
}
base.ID = id
return nil
}