Documentation
¶
Overview ¶
Package entity contains all the structs that will be used to build tables in the database.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Role ¶
type Role struct { ID int `gorm:"type:serial;primaryKey" json:"id"` Name string `gorm:"type:varchar(255) not null unique" json:"name"` Description string `gorm:"type:varchar(255) not null" json:"description"` TimeFields }
type Table ¶
type Table interface {
TableName() string
}
Table interface is contract that make developer not forget to add TableName method for struct
type TimeFields ¶
type TimeFields struct { CreatedAt *time.Time `gorm:"type:timestamp null;default:null" json:"created_at"` UpdatedAt *time.Time `gorm:"type:timestamp null;default:null" json:"updated_at"` DeletedAt *time.Time `gorm:"type:timestamp null;default:null" json:"deleted_at"` }
TimeFields struct used by almost all entity. This struct give stabillity for creating more and more entity/ struct/ table. This struct prevents developers from making typing errors / typo.
func (*TimeFields) SetCreateTime ¶
func (att *TimeFields) SetCreateTime()
SetCreateTime func fills created_at and updated_at fields This struct prevents developers from forgets or any common mistake.
func (*TimeFields) SetDeleteTime ¶
func (att *TimeFields) SetDeleteTime()
SetDeleteTime func fills deleted_at fields and for status in softdelete feature This struct prevents developers from forgets or any common mistake.
func (*TimeFields) SetUpdateTime ¶
func (att *TimeFields) SetUpdateTime()
SetUpdateTime func fills updated_at fields This struct prevents developers from forgets or any common mistake.
type User ¶
type User struct { ID int `gorm:"type:bigserial;primaryKey" json:"id"` Name string `gorm:"type:varchar(100) not null" json:"name"` Email string `gorm:"type:varchar(100) not null unique" json:"email"` Password string `gorm:"type:varchar(255) not null" json:"password"` ActivatedAt *time.Time `gorm:"type:timestamp null;default:null" json:"activated_at"` Roles []Role `gorm:"many2many:user_has_roles" json:"roles"` TimeFields }
type UserHasRoles ¶
type UserHasRoles struct { UserID int `json:"user_id"` User User `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"user"` RoleID int `json:"role_id"` Role Role `gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"role"` }
func (*UserHasRoles) TableName ¶
func (e *UserHasRoles) TableName() string