BREAKING CHANGE: V2 of thr SDK #12

Merged
fenpaws merged 124 commits from develop/postgresql into main 2024-07-01 20:46:28 +00:00
Showing only changes of commit 31c4249129 - Show all commits

View File

@ -7,27 +7,26 @@ import (
)
type ID interface {
AnthroveUserID
AnthroveSourceID
AnthrovePostID
AnthroveUserID | AnthroveSourceID | AnthrovePostID
}
type BaseModel struct {
ID string `gorm:"primaryKey"`
type BaseModel[T ID] struct {
ID T `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
func (base *BaseModel) BeforeCreate(db *gorm.DB) error {
func (base *BaseModel[T]) BeforeCreate(db *gorm.DB) error {
var defaultVar T
if base.ID == "" {
if base.ID == defaultVar {
id, err := gonanoid.New(25)
if err != nil {
return err
}
base.ID = id
base.ID = T(id)
}
return nil