This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Base struct {
|
||||
ID string `gorm:"type:string;primary_key;"`
|
||||
CreatedAt time.Time `json:"created_date"`
|
||||
UpdatedAt time.Time `json:"last_modified_date"`
|
||||
DeletedAt *time.Time `json:"deleted_date"`
|
||||
Version int `gorm:"default:0" json:"version"`
|
||||
}
|
||||
|
||||
// BeforeCreate will set a UUID rather than numeric ID.
|
||||
func (b *Base) BeforeCreate(tx *gorm.DB) (err error) {
|
||||
b.ID = uuid.New().String()
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user