models

package
Version: v0.0.0-...-16c7906 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	// 注意字段名一般为首字母大写;反引号+(主键pk,自增auto)
	Id    int    `orm:"pk;auto"`
	Aname string `orm:"size(20)"`
	// auto_now 每次model保存时都会对时间自动更新
	Atime    time.Time    `orm:"auto_now"`
	Acount   int          `orm:"default(0);null"`
	Acontent string       // 文章内容
	Aimg     string       // 文章存放路径
	Atype    *ArticleType `orm:"rel(fk)"` //设置一对多关系,一篇文章对应一个类型,文章类型为外键
	User     *User        `orm:"rel(fk)"` //设置一对多的关系,一篇文章对应一个创建者
}

文章表

type ArticleType

type ArticleType struct {
	Id       int
	Typename string     `orm:"size(20)"`
	Articles []*Article `orm:"reverse(many)"` // 设置一对多的反向关系,一个类型可以包含多篇文章
}

文章类型表

type User

type User struct {
	Name     string `orm:"pk"`
	Pwd      string
	Articles []*Article `orm:"reverse(many)"` // 设置一对多关系,一个用户可以发表多篇文章
}

一共有3张表 用户表

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL