Answers for "gorm uuid"

Go
0

gorm uuid

package model

import (
	"time"

	"github.com/google/uuid"
	"gorm.io/gorm"
)

type EntityUsers struct {
	ID        string `gorm:"primaryKey;"`
	Fullname  string `gorm:"type:varchar(255);unique;not null"`
	Email     string `gorm:"type:varchar(255);unique;not null"`
	Password  string `gorm:"type:varchar(255);not null"`
	Active    bool   `gorm:"type:bool;default:false"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func (user *EntityUsers) BeforeCreate(db *gorm.DB) error {
	user.ID = uuid.New().String()
	return nil
}
Posted by: Guest on April-25-2021

Browse Popular Code Answers by Language