models

package
v0.0.0-...-d068a9b Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DB *gorm.DB

Functions

func CountComment

func CountComment() int

func CountPage

func CountPage() int

func CountPost

func CountPost() int

func CountPostByArchive

func CountPostByArchive(year, month string) (count int, err error)

func CountPostByTag

func CountPostByTag(tag string) (count int, err error)

func CountSubscriber

func CountSubscriber() (int, error)

func CountTag

func CountTag() int

func DeletePostTagByPostId

func DeletePostTagByPostId(postId uint) error

func InitDB

func InitDB() (*gorm.DB, error)

建立DB的连接,并初始化表.

func SetAllCommentRead

func SetAllCommentRead() error

Types

type BaseModel

type BaseModel struct {
	ID        uint `gorm:"primary_key"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

I don't need soft delete,so I use customized BaseModel instead gorm.Model

type Comment

type Comment struct {
	BaseModel
	UserID    uint   // 用户id
	Content   string // 内容
	PostID    uint   // 文章id
	ReadState bool   `gorm:"default:'0'"` // 阅读状态
	//Replies []*Comment // 评论
	NickName  string `gorm:"-"`
	AvatarUrl string `gorm:"-"`
	GithubUrl string `gorm:"-"`
}

table comments

func ListCommentByPostID

func ListCommentByPostID(postId string) ([]*Comment, error)

func ListUnreadComment

func ListUnreadComment() ([]*Comment, error)

func MustListUnreadComment

func MustListUnreadComment() []*Comment

func (*Comment) Delete

func (comment *Comment) Delete() error

func (*Comment) Insert

func (comment *Comment) Insert() error

Comment

func (*Comment) Update

func (comment *Comment) Update() error
type Link struct {
	gorm.Model
	Name string //名称
	Url  string //地址
	Sort int    `gorm:"default:'0'"` //排序
	View int    //访问次数
}

table link

func GetLinkById

func GetLinkById(id uint) (*Link, error)
func ListLinks() ([]*Link, error)
func MustListLinks() []*Link

func (*Link) Delete

func (link *Link) Delete() error

func (*Link) Insert

func (link *Link) Insert() error

Link

func (*Link) Update

func (link *Link) Update() error

type Page

type Page struct {
	BaseModel
	Title       string // title
	Body        string // body
	View        int    // view count
	IsPublished bool   // published or not
}

table pages

func GetPageById

func GetPageById(id string) (*Page, error)

func ListAllPage

func ListAllPage() ([]*Page, error)

func ListPublishedPage

func ListPublishedPage() ([]*Page, error)

func (*Page) Delete

func (page *Page) Delete() error

func (*Page) Insert

func (page *Page) Insert() error

Page

func (*Page) Update

func (page *Page) Update() error

func (*Page) UpdateView

func (page *Page) UpdateView() error

type Post

type Post struct {
	BaseModel
	Title        string     // title
	Body         string     // body
	View         int        // view count
	IsPublished  bool       // published or not
	Tags         []*Tag     `gorm:"-"` // tags of post
	Comments     []*Comment `gorm:"-"` // comments of post
	CommentTotal int        `gorm:"-"` // count of comment
}

table posts

func GetPostById

func GetPostById(id string) (*Post, error)

func ListAllPost

func ListAllPost(tag string) ([]*Post, error)

func ListMaxCommentPost

func ListMaxCommentPost() (posts []*Post, err error)

func ListMaxReadPost

func ListMaxReadPost() (posts []*Post, err error)

func ListPostByArchive

func ListPostByArchive(year, month string, pageIndex, pageSize int) ([]*Post, error)

func ListPublishedPost

func ListPublishedPost(tag string, pageIndex, pageSize int) ([]*Post, error)

分页查询数据

func MustListMaxCommentPost

func MustListMaxCommentPost() (posts []*Post)

func MustListMaxReadPost

func MustListMaxReadPost() (posts []*Post)

func (*Post) Delete

func (post *Post) Delete() error

func (*Post) Excerpt

func (post *Post) Excerpt() template.HTML

func (*Post) Insert

func (post *Post) Insert() error

Post

func (*Post) Update

func (post *Post) Update() error

func (*Post) UpdateView

func (post *Post) UpdateView() error

type PostTag

type PostTag struct {
	BaseModel
	PostId uint // post id
	TagId  uint // tag id
}

table post_tags

func (*PostTag) Insert

func (pt *PostTag) Insert() error

post_tags

type QrArchive

type QrArchive struct {
	ArchiveDate time.Time //month
	Total       int       //total
	Year        int       // year
	Month       int       // month
}

query result

func ListPostArchives

func ListPostArchives() ([]*QrArchive, error)

func MustListPostArchives

func MustListPostArchives() []*QrArchive

type SmmsFile

type SmmsFile struct {
	BaseModel
	FileName  string `json:"filename"`
	StoreName string `json:"storename"`
	Size      int    `json:"size"`
	Width     int    `json:"width"`
	Height    int    `json:"height"`
	Hash      string `json:"hash"`
	Delete    string `json:"delete"`
	Url       string `json:"url"`
	Path      string `json:"path"`
}

func (SmmsFile) Insert

func (sf SmmsFile) Insert() (err error)

type Subscriber

type Subscriber struct {
	gorm.Model
	Email          string    `gorm:"unique_index"` //邮箱
	VerifyState    bool      `gorm:"default:'0'"`  //验证状态
	SubscribeState bool      `gorm:"default:'1'"`  //订阅状态
	OutTime        time.Time //过期时间
	SecretKey      string    // 秘钥
	Signature      string    //签名
}

table subscribe

func GetSubscriberByEmail

func GetSubscriberByEmail(mail string) (*Subscriber, error)

func GetSubscriberById

func GetSubscriberById(id uint) (*Subscriber, error)

func GetSubscriberBySignature

func GetSubscriberBySignature(key string) (*Subscriber, error)

func ListSubscriber

func ListSubscriber(invalid bool) ([]*Subscriber, error)

func (*Subscriber) Insert

func (s *Subscriber) Insert() error

Subscriber

func (*Subscriber) Update

func (s *Subscriber) Update() error

type Tag

type Tag struct {
	BaseModel
	Name  string // tag name
	Total int    `gorm:"-"` // count of post
}

table tags

func ListAllTag

func ListAllTag() ([]*Tag, error)

func ListTag

func ListTag() ([]*Tag, error)

func ListTagByPostId

func ListTagByPostId(id string) ([]*Tag, error)

func MustListTag

func MustListTag() []*Tag

func (*Tag) Insert

func (tag *Tag) Insert() error

Tag

type User

type User struct {
	gorm.Model
	Email         string    `gorm:"unique_index;default:null"` //邮箱
	Telephone     string    `gorm:"unique_index;default:null"` //手机号码
	Password      string    `gorm:"default:null"`              //密码
	VerifyState   string    `gorm:"default:'0'"`               //邮箱验证状态
	SecretKey     string    `gorm:"default:null"`              //密钥
	OutTime       time.Time //过期时间
	GithubLoginId string    `gorm:"unique_index;default:null"` // github唯一标识
	GithubUrl     string    //github地址
	IsAdmin       bool      //是否是管理员
	AvatarUrl     string    // 头像链接
	NickName      string    // 昵称
	LockState     bool      `gorm:"default:'0'"` //锁定状态
}

table users

func GetUser

func GetUser(id interface{}) (*User, error)

func GetUserByUsername

func GetUserByUsername(username string) (*User, error)

func IsGithubIdExists

func IsGithubIdExists(githubId string, id uint) (*User, error)

func ListUsers

func ListUsers() ([]*User, error)

func (*User) FirstOrCreate

func (user *User) FirstOrCreate() (*User, error)

func (*User) Insert

func (user *User) Insert() error

user insert user

func (*User) Lock

func (user *User) Lock() error

func (*User) Update

func (user *User) Update() error

update user

func (*User) UpdateEmail

func (user *User) UpdateEmail(email string) error

func (*User) UpdateGithubUserInfo

func (user *User) UpdateGithubUserInfo() error

func (*User) UpdateProfile

func (user *User) UpdateProfile(avatarUrl, nickName string) error

Jump to

Keyboard shortcuts

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