orm

package
v0.0.0-...-abc415f Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DB

func DB() *gorm.DB

DB 返回 *gorm.DB

func ScopesCursorID

func ScopesCursorID(id int64) func(db *gorm.DB) *gorm.DB

ScopesCursorID 生成ID查询条件

func ScopesCursorRank

func ScopesCursorRank(rank float64) func(db *gorm.DB) *gorm.DB

ScopesCursorRank 生成rank查询条件

func ScopesTag

func ScopesTag(tags []int64) func(db *gorm.DB) *gorm.DB

ScopesTag 生成tag查询条件

Types

type Article

type Article struct {
	ID      uint      `gorm:"primary_key"`
	Title   string    // 标题
	Author  string    // 作者
	Cover   string    // 封面
	Intro   string    // 介绍
	PubAt   time.Time `sql:"index"` // 微信文章发布时间
	MediaID uint
	// Media     Media
	Like      int64         `gorm:"default:0"`
	Hate      int64         `gorm:"default:0"`
	View      int64         `gorm:"default:0"`                      // 点击次数,通过它进行计算排名
	URL       string        `gorm:"type:varchar(255);unique_index"` // 微信文章地址
	Rank      float64       `sql:"index"`                           // 排行
	Tags      pq.Int64Array `gorm:"type:int[]"`                     // 标签
	State     int
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
}

Article 文章列表

func (*Article) GetArticle

func (article *Article) GetArticle(limit, offset, tag int, order string) (articles []Article)

GetArticle 获取文章

func (*Article) GetArticleByID

func (article *Article) GetArticleByID(id int)

GetArticleByID 获取Article

func (*Article) GetArticleByURL

func (article *Article) GetArticleByURL(url string)

GetArticleByURL 通过url获取Article 如果没有的话进行初始化 (注:此url由文章详细页获得)

func (*Article) GetArticleCursorByID

func (article *Article) GetArticleCursorByID(id, limit int, tags []int64) (articles []Article)

GetArticleCursorByID 以ID为游标获取数据

func (*Article) GetArticleCursorByRank

func (article *Article) GetArticleCursorByRank(rank float64, limit int, tags []int64) (articles []Article)

GetArticleCursorByRank 以Rank为游标获取数据

func (*Article) GetArticleCursorByRankForFullText

func (article *Article) GetArticleCursorByRankForFullText(text string, rank float64, limit int) (articles []Article)

GetArticleCursorByRankForFullText 以Rank为游标 搜索文章标题

func (*Article) GetHotArticleByTag

func (article *Article) GetHotArticleByTag(limit, offset, tag int) (articles []Article)

GetHotArticleByTag 获取文章

func (*Article) GetNewArticleByTag

func (article *Article) GetNewArticleByTag(limit, offset, tag int) (articles []Article)

GetNewArticleByTag 获取文章

func (*Article) Hot

func (article *Article) Hot(limit, offset int) (articles []Article)

Hot 热门

func (*Article) New

func (article *Article) New(limit, offset int) (articles []Article)

New 最新

func (*Article) Save

func (article *Article) Save()

Save 保存用户信息

type Media

type Media struct {
	ID        uint   `gorm:"primary_key"`
	AppID     string `gorm:"type:varchar(100);unique_index"`
	AppName   string
	Cover     string
	Intro     string
	State     int
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time    `sql:"index"`
	Tags      pq.Int64Array `gorm:"type:int[]"` // 标签(文章继承)
	Articles  []Article
}

Media 微信公众号

func (*Media) GetMediaByAppID

func (media *Media) GetMediaByAppID(appID string)

GetMediaByAppID appID 获取公众号

func (*Media) GetMediaByID

func (media *Media) GetMediaByID(id int)

GetMediaByID 获取 Media

func (*Media) Save

func (media *Media) Save()

Save 保存

type Post

type Post struct {
	ID         uint   `gorm:"primary_key"`
	URL        string `gorm:"type:varchar(255);unique_index"`
	ArticleURL string
	State      int
	CreatedAt  time.Time
	UpdatedAt  time.Time
	DeletedAt  *time.Time `sql:"index"`
}

Post has and belongs to many languages, use `Post_languages` as join table

func (*Post) GetPostByID

func (post *Post) GetPostByID(id int)

GetPostByID 获取post

func (*Post) GetPostByURL

func (post *Post) GetPostByURL(url string)

GetPostByURL 通过url获取post 如果没有的话进行初始化 (注:此url由文章详细页获得)

func (*Post) Save

func (post *Post) Save()

Save 保存用户信息

type Tag

type Tag struct {
	ID        uint `gorm:"primary_key"`
	Pid       uint
	IsShow    int
	Type      string
	Title     string
	Name      string `gorm:"type:varchar(100);unique_index"`
	Intro     string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time `sql:"index"`
}

Tag 标签属性 (不存在相同的标签)

func (*Tag) GetAllTags

func (tag *Tag) GetAllTags() (tags []Tag)

GetAllTags 获取所有 Tags

func (*Tag) GetTagByID

func (tag *Tag) GetTagByID(id int)

GetTagByID 获取 Tag

func (*Tag) GetTagByName

func (tag *Tag) GetTagByName(name string)

GetTagByName 通过名词获取标签

func (*Tag) GetTagsByIDS

func (tag *Tag) GetTagsByIDS(ids []int64) (tags []Tag)

GetTagsByIDS 通过ID获取标签

func (*Tag) GetTagsByLikeTitle

func (tag *Tag) GetTagsByLikeTitle(name string) (tags []Tag)

GetTagsByLikeTitle 通过属性获取标签

func (*Tag) GetTagsByTitle

func (tag *Tag) GetTagsByTitle(name string) (tags []Tag)

GetTagsByTitle 通过属性获取标签

func (*Tag) GetTagsByType

func (tag *Tag) GetTagsByType(name string) (tags []Tag)

GetTagsByType 通过属性获取标签

func (*Tag) Save

func (tag *Tag) Save()

Save 保存用户信息

Jump to

Keyboard shortcuts

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