model

package
v0.0.0-...-49bf833 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2023 License: MIT Imports: 5 Imported by: 0

README

model layer

  • model 层就是数据库表字段的 Go 结构体映射
  • 根据业务需求,用 dBlog 数据库中的表来创建 Model

user 表代码 post 表代码

  • 借助工具自动生成结构体代码
    • 创建数据库和数据库表
    • 根据数据库表生成 Model 文件
    • 优化代码

SQL 语句存储

  • 为了以后的部署,将创建数据库以及数据库表的 SQL 语句存储在了 dBlog.sql 文件中
mysqldump -h127.0.0.1 -udazblog --databases dazblog -p'passwd' --add-drop-database --add-drop-table --add-drop-trigger --add-locks --no-data > configs/dBblog.sql

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AIM

type AIM struct {
	ID       int64  `gorm:"column:id;primary_key"`     // unique id of the ai content, server as the primary key
	Username string `gorm:"column:username"`           // author of the ai content
	PostID   string `gorm:"column:postID;primary_key"` // post of the ai content
	Content  string `gorm:"column:content"`            // content of the ai content
}

func (*AIM) TableName

func (u *AIM) TableName() string

type PostM

type PostM struct {
	ID        int64     `gorm:"column:id;primary_key"` // unique id for the post, server as the primary key
	Username  string    `gorm:"column:username"`       //	author of the post
	PostID    string    `gorm:"column:postID"`         //	unique id for the post, used as a user-friendly ID
	Title     string    `gorm:"column:title"`          //	title of the post
	Content   string    `gorm:"column:content"`        // content of the post
	CreatedAt time.Time `gorm:"column:createdAt"`      // time when the post was created
	UpdatedAt time.Time `gorm:"column:updatedAt"`      // time when the post was updated
}

func (*PostM) AfterCreate

func (p *PostM) AfterCreate(tx *gorm.DB) error

func (*PostM) BeforeCreate

func (p *PostM) BeforeCreate(tx *gorm.DB) error

func (*PostM) TableName

func (p *PostM) TableName() string

TableName sets the insert table name for this struct type

type UserM

type UserM struct {
	ID        int64     `gorm:"column:id;primary_key"` // unique id for the user, server as the primary key
	PostCount int64     `gorm:"column:postcount"`      // number of posts the user has
	Username  string    `gorm:"column:username"`       // username of the user
	Password  string    `gorm:"column:password"`       // password of the user
	Nickname  string    `gorm:"column:nickname"`       // nickname of the user
	Email     string    `gorm:"column:email"`          // email of the user
	Gender    string    `gorm:"column:gender"`         // gender of the user
	Phone     string    `gorm:"column:phone"`          // phone number of the user
	QQ        string    `gorm:"column:qq"`             // qq number of the user
	CreatedAt time.Time `gorm:"column:createdAt"`      // time when the user was created
	UpdatedAt time.Time `gorm:"column:updatedAt"`      // time when the user was updated
}

func (*UserM) BeforeCreate

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

BeforeCreate will encrypt the user password before creating the user

func (*UserM) TableName

func (u *UserM) TableName() string

TableName sets the insert table name for this struct type

Jump to

Keyboard shortcuts

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