database

package
v0.0.0-...-5c0bb04 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const TablePrefix = "mc_"

TablePrefix db table prefix

Variables

This section is empty.

Functions

func Has

func Has(db *gorm.DB, model TableInterface, scopes ...func(*gorm.DB) *gorm.DB) (bool, error)

Has does it exist

func WithTablePrefix

func WithTablePrefix(model string) string

WithTablePrefix return a string with table prefix append model

Types

type TableInterface

type TableInterface interface {
	TableName() string
	PrimaryKey() string
}

TableInterface database table functions

type User

type User struct {
	ID                     uint   `gorm:"COLUMN:user_id;TYPE:INT(11) UNSIGNED;NOT NULL;autoIncrement;primaryKey;->;COMMENT:用户ID" json:"user_id"`
	Username               string `gorm:"TYPE:VARCHAR(20);NOT NULL;INDEX:user_name;COMMENT:用户名" json:"username"`
	Email                  string `gorm:"TYPE:VARCHAR(320) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;NOT NULL;INDEX:email;COMMENT:邮箱" json:"email"`
	Avatar                 string `gorm:"TYPE:VARCHAR(50);COMMENT:头像token" json:"-"`
	Cover                  string `gorm:"TYPE:VARCHAR(50);COMMENT:封面图片token" json:"-"`
	Password               string `gorm:"TYPE:VARCHAR(255);NOT NULL;COMMENT:密码" json:"-"`
	CreateIP               string `gorm:"TYPE:VARCHAR(80);COMMENT:注册IP" json:"create_ip"`
	CreateLocation         string `gorm:"TYPE:VARCHAR(100);COMMENT:注册地址" json:"create_location"`
	LastLoginTime          uint64 `gorm:"TYPE:INT(10) UNSIGNED;DEFAULT:0;NOT NULL;COMMENT:最后登录时间" json:"last_login_time"`
	LastLoginIP            string `gorm:"TYPE:VARCHAR(80);COMMENT:最后登陆IP" json:"last_login_ip"`
	LastLoginLocation      string `gorm:"TYPE:VARCHAR(100);COMMENT:最后登录地址" json:"last_login_location"`
	FollowerCount          uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;INDEX:follower_count;COMMENT:关注我的人数" json:"follower_count"`
	FolloweeCount          uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我关注的人数" json:"followee_count"`
	FollowingArticleCount  uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我关注的文章数" json:"following_article_count"`
	FollowingQuestionCount uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我关注的问题数" json:"following_question_count"`
	FollowingTopicCount    uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我关注的话题数" json:"following_topic_count"`
	ArticleCount           uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我发表的文章数量" json:"article_count"`
	QuestionCount          uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我发表的问题数量" json:"question_count"`
	AnswerCount            uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:我发表的回答数量" json:"answer_count"`
	NotificationUnread     uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:未读通知数" json:"notification_unread"`
	InboxUnread            uint   `gorm:"TYPE:INT(11) UNSIGNED;NOT NULL;DEFAULT:0;COMMENT:未读私信数" json:"inbox_unread"`
	Headline               string `gorm:"TYPE:VARCHAR(40) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;COMMENT:一句话介绍" json:"headline"`
	Bio                    string `gorm:"TYPE:VARCHAR(160);COMMENT:个人简介" json:"bio"`
	Blog                   string `gorm:"TYPE:VARCHAR(255);COMMENT:个人主页" json:"blog"`
	Company                string `gorm:"TYPE:VARCHAR(255);COMMENT:公司名称" json:"company"`
	Location               string `gorm:"TYPE:VARCHAR(255);COMMENT:地址" json:"location"`
	CreateTime             uint64 `gorm:"autoCreateTime;TYPE:INT(10) UNSIGNED;INDEX:create_time;DEFAULT:0;NOT NULL;COMMENT:注册时间" json:"create_time"`
	UpdateTime             uint64 `gorm:"autoUpdateTime;TYPE:INT(10) UNSIGNED;DEFAULT:0;NOT NULL;COMMENT:更新时间" json:"update_time"`
	DisableTime            uint64 `gorm:"TYPE:INT(10) UNSIGNED;DEFAULT:0;NOT NULL;COMMENT:禁用时间" json:"disable_time"`
}

User db table with user

func Register

func Register(db *gorm.DB, ctx echo.Context, username, email, password string) (*User, error)

Register add a user save to database

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

BeforeCreate before create action for user

func (User) PrimaryKey

func (User) PrimaryKey() string

func (User) TableName

func (User) TableName() string

TableName return user table name

Jump to

Keyboard shortcuts

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