entity

package
v0.0.0-...-3839eb7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 5, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *gorm.DB) error

Migrate auto migration all the table defined

Types

type APIKey

type APIKey struct {
	Key    string `json:"key"`
	UserId string `json:"userId"`

	Name  string `json:"name"`
	Perms []uint `json:"perms"`

	CreatedAt uint64 `json:"createdAt"`
	ExpiredAt uint64 `json:"expiredAt"`
}

type Dict

type Dict struct {
	Id uint `gorm:"primaryKey;"`

	Name string `gorm:"type:varchar(100);"`
	Code string `gorm:"type:varchar(100);"`

	Data []DictData

	CreatedAt uint64 `gorm:"autoCreateTime:nano;"`
	UpdatedAt uint64 `gorm:"autoUpdateTime:nano;"`
}

func (Dict) TableComment

func (d Dict) TableComment() string

func (Dict) TableName

func (d Dict) TableName() string

type DictData

type DictData struct {
	Id uint `gorm:"primaryKey;"`

	Name  string `gorm:"type:varchar(100);comment:data name;"`
	Key   string `gorm:"type:varchar(100);uniqueIndex;comment:data key;"`
	Value string `gorm:"type:varchar(255);comment:data value;"`
	Type  uint8  `gorm:"comment:data type"`
	Order int    `gorm:"comment:order flag;"`

	CreatedAt uint64         `gorm:"autoCreateTime:nano;"`
	UpdatedAt uint64         `gorm:"autoUpdateTime:nano;"`
	DeletedAt gorm.DeletedAt `gorm:"index;comment:disable status;"`

	DictId uint `gorm:"comment:dict type reference key;"`
}

func (DictData) DataValue

func (d DictData) DataValue() (any, error)

func (DictData) TableComment

func (d DictData) TableComment() string

func (DictData) TableName

func (d DictData) TableName() string

type Permission

type Permission struct {
	PermissionTable

	Id     uint   `gorm:"primarykey"`
	Name   string `gorm:"type:varchar(50);comment:perm name;"`
	Object string `gorm:"type:varchar(100);uniqueIndex:perm;comment:resource will be accessed;"`
	Action string `gorm:"type:varchar(50);uniqueIndex:perm;comment:resource action;"`
	Group  string `gorm:"type:varchar(30);uniqueIndex:perm;comment:permission group;"`
	Tag    string `gorm:"type:varchar(30);uniqueIndex:perm;comment:perm's tag,define type of perm;"`

	CreatedAt uint64 `gorm:"autoCreateTime:nano;"`
	UpdatedAt uint64 `gorm:"autoUpdateTime:nano;"`

	Roles []Role `gorm:"many2many:role_permission;"`
}

Permission app permissions record table

type PermissionTable

type PermissionTable struct{}

func (PermissionTable) BeforeCreate

func (p PermissionTable) BeforeCreate(db *gorm.DB) error

func (PermissionTable) TableComment

func (p PermissionTable) TableComment() string

func (PermissionTable) TableName

func (p PermissionTable) TableName() string

type Role

type Role struct {
	RoleTable
	Id   uint   `gorm:"primarykey"`
	Name string `gorm:"type:varchar(50);comment:role display name;"`
	Code string `gorm:"type:varchar(50);uniqueIndex;comment:role code;"`

	CreatedAt uint64 `gorm:"autoCreateTime:nano;"`
	UpdatedAt uint64 `gorm:"autoUpdateTime:nano;"`

	Perms []Permission `gorm:"many2many:role_permission;"`
	Users []User       `gorm:"many2many:users_roles;"`
}

Role app roles record table

type RolePermission

type RolePermission struct {
	PermissionId uint       `gorm:"primaryKey;comment:id of permission;"`
	Permission   Permission `gorm:"foreignKey:PermissionId;"`

	RoleId uint `gorm:"primaryKey;comment:id of role;"`
	Role   Role `gorm:"foreignKey:RoleId;"`

	RolePermissionTable
}

RolePermission role-permission relation table

func (RolePermission) BeforeCreate

func (r RolePermission) BeforeCreate(db *gorm.DB) error

type RolePermissionTable

type RolePermissionTable struct{}

func (RolePermissionTable) TableComment

func (r RolePermissionTable) TableComment() string

func (RolePermissionTable) TableName

func (r RolePermissionTable) TableName() string

type RoleTable

type RoleTable struct{}

func (RoleTable) BeforeCreate

func (r RoleTable) BeforeCreate(db *gorm.DB) error

func (RoleTable) TableComment

func (r RoleTable) TableComment() string

func (RoleTable) TableName

func (r RoleTable) TableName() string

type Table

type Table interface {
	TableName() string
	TableComment() string
}

Table represents an entity for table

type User

type User struct {
	UserTable

	Id       uint   `gorm:"primaryKey;"`
	UUID     string `gorm:"uniqueIndex;type:varchar(70);comment:User UUID;"`
	Username string `gorm:"uniqueIndex;type:varchar(50);comment:username;"`
	Password string `gorm:"comment:User password;type:varchar(255);"`
	Email    string `gorm:"uniqueIndex;type:varchar(80);comment:User concat email;"`

	CreatedAt uint64 `gorm:"autoCreateTime:nano;"`
	UpdatedAt uint64 `gorm:"autoUpdateTime:nano;"`

	Roles []Role `gorm:"many2many:users_roles;"`
}

User user entity represents from database table

type UserRole

type UserRole struct {
	UserId uint `gorm:"primaryKey;comment:id of user who own role;"`
	User   User `gorm:"foreignKey:UserId;"`

	RoleId uint `gorm:"primaryKey;comment:id of role;"`
	Role   Role `gorm:"foreignKey:RoleId;"`

	UserRoleTable
}

UserRole user-role relation table

func (UserRole) BeforeCreate

func (u UserRole) BeforeCreate(db *gorm.DB) error

type UserRoleTable

type UserRoleTable struct{}

func (UserRoleTable) BeforeCreate

func (u UserRoleTable) BeforeCreate(db *gorm.DB) error

func (UserRoleTable) TableComment

func (u UserRoleTable) TableComment() string

func (UserRoleTable) TableName

func (u UserRoleTable) TableName() string

type UserTable

type UserTable struct{}

func (UserTable) BeforeCreate

func (u UserTable) BeforeCreate(db *gorm.DB) error

func (UserTable) TableComment

func (u UserTable) TableComment() string

func (UserTable) TableName

func (u UserTable) TableName() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL