Documentation
¶
Overview ¶
Package model 尝试缓存友好的编写
log db @since 0.0.4
Index ¶
- Variables
- func AppendMap(a gin.H, b gin.H) gin.H
- func BatchUpdate(arr []DBBookTaxonomy) error
- func EditCategory(termID uint64, name string, slug string, description string, parent uint64) error
- func GetDBPostmetas(postID uint64) (map[string]DBPostmeta, error)
- func GetOption(name string) string
- func GetStructFieldTag(i interface{}, tagName string) (tableField []string)
- func InsertMenu(name string, slug string, description string) error
- func InsertMenuItem(postTitle string, url string, termTaxonomyID uint64) error
- func InsterCategory(name string, parent uint64, slug string, description string) error
- func Register()
- func SetOption(name string, value string, autoload string) error
- func UpdateMenuTree(tree []Tree, parent uint64, i int) (int, error)
- func UseSchema(schema string)
- func WriteLogToDB(desc string, requestID string, logType LogsLogType)
- type BaseTplData
- type BookTaxonomyLevel
- type CardState
- type Category
- type Comment
- type DBBook
- type DBBookTaxonomy
- type DBCard
- type DBCoupon
- type DBCouponLog
- type DBCreditLog
- type DBGoods
- type DBLogs
- type DBPost
- type DBPostmeta
- type DBTerm
- type DBTermRelationship
- type DBTermTaxonomy
- type DBUsermeta
- type DBUsers
- type Label
- type LogsLogType
- type NavMenu
- type OptionNamePrefix
- type Post
- type SubMenu
- type SubMenus
- type Tag
- type Taxonomy
- type TermRelationship
- type Tree
- type UserStatus
Constants ¶
This section is empty.
Variables ¶
var Create create
var CreateSQLPath = "./data/sql"
var DB *sql.DB
DB 数据库接口 @since 0.0.1
var DB8 *sql.DB
var DBX *sqlx.DB
var ErrEmptyResult = scanner.ErrEmptyResult
var GDB *gorm.DB
var Insert insert
Insert 插入基础数据
var Null null
Null 用于安全获取结构体零值 @since 0.0.1
Functions ¶
func EditCategory ¶
EditCategory 编辑分类 @since 0.0.1
func GetDBPostmetas ¶ added in v0.0.5
func GetDBPostmetas(postID uint64) (map[string]DBPostmeta, error)
GetDBPostmetas post_id @since 0.0.4
func GetOption ¶
GetOption 获取 option @since 0.0.1 func GetOption(ctx context.Context, name string) string {
func GetStructFieldTag ¶ added in v0.0.10
getSelectField
func InsertMenu ¶
InsertMenu 添加菜单 @since 0.0.1
func InsertMenuItem ¶
InsertMenuItem 添加菜单项 @since 0.0.1
func InsterCategory ¶
InsterCategory 添加菜单 @since 0.0.1
func Register ¶
func Register()
Register 注册数据库 @since 0.0.1 @since 0.0.4 引入字段绑定 func Register(ctx context.Context) {
func UpdateMenuTree ¶
UpdateMenuTree 更新菜单顺序 @since 0.0.1
func WriteLogToDB ¶ added in v0.0.5
func WriteLogToDB(desc string, requestID string, logType LogsLogType)
Types ¶
type BaseTplData ¶
BaseTplData 基础模板变量值 @since 0.0.1
type BookTaxonomyLevel ¶
type BookTaxonomyLevel int
const ( BookTaxonomyLevelFirst BookTaxonomyLevel = 1 BookTaxonomyLevelSecond BookTaxonomyLevel = 2 BookTaxonomyLevelThird BookTaxonomyLevel = 3 BookTaxonomyLevelFourth BookTaxonomyLevel = 4 BookTaxonomyLevelFifth BookTaxonomyLevel = 5 )
type Category ¶
type Category struct {
ID uint64 `json:"id" gorm:"column:term_taxonomy_id"` // term_taxonomy_id
Name string `json:"name"` // name
Description string `json:"description"` // description
Count int64 `json:"count"` // count
Parent uint64 `json:"parent"` // parent
Slug string `json:"slug"` // slug
Taxonomy string `json:"taxonomy"` // taxonomy
Order int `json:"order"`
SubCategorys []*Category `json:"subCategorys"` // sub_categorys
}
Category 文章分类结构体 对应底层 Term @since 0.0.1
func GetAllCategory ¶
GetAllCategory fuck 完成 @since 0.0.1
func GetCategoryByTermID ¶
GetCategoryByTermID 通过id获取 category @since 0.0.1
func GetCategorys ¶
GetCategorys 通过视图的形式优化获取分类的调用 @since 0.0.1
type Comment ¶
type Comment struct {
CommentID uint64 `json:"comment_ID"` // comment_ID
CommentPostID uint64 `json:"comment_post_ID"` // comment_post_ID
CommentAuthor string `json:"comment_author"` // comment_author
CommentAuthorEmail string `json:"comment_author_email"` // comment_author_email
CommentAuthorURL string `json:"comment_author_url"` // comment_author_url
CommentAuthorIP string `json:"comment_author_IP"` // comment_author_IP
CommentDate time.Time `json:"comment_date"` // comment_date
CommentDateGMT time.Time `json:"comment_date_gmt"` // comment_date_gmt
CommentContent string `json:"comment_content"` // comment_content
CommentKarma int `json:"comment_karma"` // comment_karma
CommentApproved string `json:"comment_approved"` // comment_approved
CommentAgent string `json:"comment_agent"` // comment_agent
CommentType string `json:"comment_type"` // comment_type
CommentParent uint64 `json:"comment_parent"` // comment_parent
UserID uint64 `json:"user_id"` // user_id
}
Comment 评论结构体 @since 0.0.1
type DBBook ¶
type DBBook struct {
BookID uint64 `db:"book_id"` // 主键ID
UserID uint64 `db:"user_id"` // 用户ID
Name string `db:"name"` // 卡片名称
Desc string `db:"desc"` // 卡片内容
State CardState `db:"state"` // enum 状态 ('close','open')
DateLastActivity time.Time `db:"date_last_activity"` // 最后操作时间
ShortLink string `db:"short_link"` // 短链接
Date time.Time `db:"date"` // 创建时间
}
func (DBBook) SelectField ¶ added in v0.0.10
type DBBookTaxonomy ¶
type DBBookTaxonomy struct {
// BookTaxonomyID uint64 // 关联表ID
BookID uint64 `db:"book_id"` // 所属 book ID
CardID uint64 `db:"card_id"` // card ID
Level int `db:"level"` // 等级
ParentCardID uint64 `db:"parent_card_id"` // 上级 card ID
CardOrder uint64 `db:"card_order"`
IsLeaf bool `db:"is_leaf"`
}
DBBookTaxonomy 存 book card 的依赖关系及顺序 @since 0.0.9 增加 is_leaf 字段,增加所有 db tag
func TreeToDBStruct ¶
func TreeToDBStruct(bookID uint64, order *int, parentCardID uint64, t []Tree, dbts []DBBookTaxonomy, level int) []DBBookTaxonomy
TreeToDBStruct 将前端的排序 json 转存在数据库
type DBCard ¶
type DBCard struct {
CardID uint64 `db:"card_id"` // 主键ID
UserID uint64 `db:"user_id"` // 用户ID
Name string `db:"name"` // 卡片名称
Desc string `db:"desc"` // 卡片内容
State CardState `db:"state"` // enum 状态 ('close','open')
DateLastActivity time.Time `db:"date_last_activity"` // 最后操作时间
ShortLink string `db:"short_link"` // 短链接
Date time.Time `db:"date"` // 创建时间
// @since v0.0.9
InBook bool `db:"in_book"` // 是否归属到book
}
type DBCoupon ¶ added in v0.0.5
type DBCoupon struct {
CouponID uint64 `db:"coupon_id"` // id
UID uint64 `db:"uid"`
Code string `db:"code"` // 优惠券码
Title string `db:"title"` // 优惠券标题
Excerpt string `db:"excerpt"` // 优惠券副标题
Desc string `db:"desc"` // 优惠券使用说明
Date time.Time `db:"date"` // 创建时间
DateLastActivity time.Time `db:"date_last_activity"` // 最后一次修改/使用
Nbf time.Time `db:"nbf"` // 在此时间前不可使用
Exp time.Time `db:"exp"` // 在此时间后不可使用
Maximum int `db:"maximum"` // 最大使用次数
Used int `db:"used"` // 已使用次数
Img string `db:"img"` // 列表图片地址
State int `db:"state"` // 0 关闭 1 打开
}
DBCoupon 优惠券表 @since 0.0.4
func (DBCoupon) SelectField ¶ added in v0.0.5
type DBCouponLog ¶ added in v0.0.5
type DBCouponLog struct {
CouponLogID uint64 // id
UID uint64
Code string // 优惠券码
Title string // 优惠券标题
Excerpt string // 优惠券副标题
Desc string // 优惠券使用说明
Date time.Time // 创建时间
DateLastActivity time.Time // 最后一次修改/使用
Nbf time.Time // 在此时间前不可使用
Exp time.Time // 在此时间后不可使用
Maximum int // 最大使用次数
Used int // 已使用次数
Img string // 列表图片地址
}
DBCouponLog 优惠券表使用详情 @since 0.0.4
type DBCreditLog ¶ added in v0.0.10
type DBCreditLog struct {
LogID uint64 `db:"log_id"` //mediumint(8) unsigned NOT NULL AUTO_INCREMENT,
UserID uint64 `db:"user_id"` //bigint(8) unsigned NOT NULL DEFAULT '0',
Operation string `db:"operation"` // char(3) NOT NULL DEFAULT ”,
RelatedID uint64 `db:"related_id"` //int(10) unsigned NOT NULL,
Date time.Time `db:"date"` //int(10) unsigned NOT NULL,
Extcredits1 int `db:"extcredits1"` //int(10) NOT NULL,
Extcredits2 int `db:"extcredits2"` //int(10) NOT NULL,
Extcredits3 int `db:"extcredits3"` //int(10) NOT NULL,
Extcredits4 int `db:"extcredits4"` //int(10) NOT NULL,
Extcredits5 int `db:"extcredits5"` //int(10) NOT NULL,
Extcredits6 int `db:"extcredits6"` //int(10) NOT NULL,
Extcredits7 int `db:"extcredits7"` //int(10) NOT NULL,
Extcredits8 int `db:"extcredits8"` //int(10) NOT NULL,
Reason string `db:"reason"` // varchar(45)
}
DBCredit_log @since 0.0.9
func (DBCreditLog) SelectField ¶ added in v0.0.10
func (DBCreditLog) SelectField() []string
type DBGoods ¶ added in v0.0.18
type DBGoods struct {
GoodsID uint64 `db:"goods_id"`
GoodsName string `db:"goods_name"`
GoodsPrice float64 `db:"goods_price"`
GoodsCategoryID uint64 `db:"goods_category_id"`
GoodsUID uint64 `db:"goods_uid"`
GoodsDate time.Time `db:"goods_date"`
GoodsContent string `db:"goods_content"`
GoodsExcerpt string `db:"goods_excerpt"`
GoodsStatus string `db:"goods_status"`
GoodsModified time.Time `db:"goods_modified"`
GoodsOrder uint64 `db:"goods_order"`
GoodsImg string `db:"goods_img"`
GoodsExt string `db:"goods_ext"`
}
type DBPost ¶
type DBPost struct {
ID uint64 `db:"ID" json:"ID" gorm:"primary_key;column:ID"` // ID
PostAuthor uint64 `db:"post_author" json:"post_author"` // post_author
PostDate time.Time `db:"post_date" json:"post_date"` // post_date
PostDateGmt time.Time `db:"post_date_gmt" json:"post_date_gmt"` // post_date_gmt
PostContent string `db:"post_content" json:"post_content"` // post_content
PostTitle string `db:"post_title" json:"post_title"` // post_title
PostExcerpt string `db:"post_excerpt" json:"post_excerpt"` // post_excerpt
PostStatus string `db:"post_status" json:"post_status"` // post_status
CommentStatus string `db:"comment_status" json:"comment_status"` // comment_status
PingStatus string `db:"ping_status" json:"ping_status"` // ping_status
PostPassword string `db:"post_password" json:"post_password"` // post_password
PostName string `db:"post_name" json:"post_name"` // post_name
ToPing string `db:"to_ping" json:"to_ping"` // to_ping
Pinged string `db:"pinged" json:"pinged"` // pinged
PostModified time.Time `db:"post_modified" json:"post_modified"` // post_modified
PostModifiedGmt time.Time `db:"post_modified_gmt" json:"post_modified_gmt"` // post_modified_gmt
PostContentFiltered string `db:"post_content_filtered" json:"post_content_filtered"` // post_content_filtered
PostParent uint64 `db:"post_parent" json:"post_parent"` // post_parent
GUID string `db:"guid" json:"guid"` // guid
MenuOrder int `db:"menu_order" json:"menu_order"` // menu_order
PostType string `db:"post_type" json:"post_type"` // post_type
PostMimeType string `db:"post_mime_type" json:"post_mime_type"` // post_mime_type
CommentCount int64 `db:"comment_count" json:"comment_count"` // comment_count
Tags []*Tag `db:"-"`
Comments []*Comment `db:"-"`
TermRelationships []*DBTermRelationship `db:"-"` // 用于关联文章对分类 这里应该关联 term
Postmetas []*wpsapi.Postmetum `db:"-"` // 更换成小写m
}
DBPost 文章常用结构体 TODO 只留文章用到的字段 @since 0.0.1 @since 0.0.6 TODO DB 结构体 只保留数据库字段 其他字段移动到业务结构体 post 0.0.7
func (DBPost) SelectField ¶ added in v0.0.6
SelectField @since 0.0.6
type DBPostmeta ¶ added in v0.0.5
DBPostmeta 文章属性 @since 0.0.1 @since 0.0.4 重命名 Postmeta -> DBPostmeta
type DBTerm ¶
type DBTerm struct {
TermID uint64 `json:"termID" gorm:"column:term_id;primary_key"` // term_id
Name string `json:"name"` // name
Slug string `json:"slug"` // slug
TermGroup int64 `json:"termGroup"` // term_group
// 暂时还不敢删 有一些历史关联引用
TermTaxonomy *DBTermTaxonomy
}
DBTerm 项 @since 0.0.1
type DBTermRelationship ¶
type DBTermRelationship struct {
ObjectID uint64 `json:"object_id"` // object_id
TermTaxonomyID uint64 `json:"term_taxonomy_id"` // term_taxonomy_id
TermOrder int `json:"term_order"` // term_order
}
DBTermRelationship 分类 @since 0.0.1
func GetDBTermRelationships ¶ added in v0.0.5
func GetDBTermRelationships(termTaxonomyID uint64) (*DBTermRelationship, error)
GetDBTermRelationships term_taxonomy_id @since 0.0.4
func (DBTermRelationship) TableName ¶
func (DBTermRelationship) TableName() string
TableName 数据库表名 gorm @since 0.0.1
type DBTermTaxonomy ¶
type DBTermTaxonomy struct {
TermTaxonomyID uint64 `json:"termTaxonomyID"` // term_taxonomy_id
TermID uint64 `json:"termID"` // term_id
Taxonomy string `json:"taxonomy"` // taxonomy
Description string `json:"description"` // description
Parent uint64 `json:"parent"` // parent
Count int64 `json:"count"` // count
}
DBTermTaxonomy 类型辅助结构体 @since 0.0.1
func GetDBTermTaxonomy ¶ added in v0.0.5
func GetDBTermTaxonomy(termID uint64) (*DBTermTaxonomy, error)
GetDBTermTaxonomy term_id @since 0.0.4
func (DBTermTaxonomy) TableName ¶
func (DBTermTaxonomy) TableName() string
TableName 表名 gorm @since 0.0.1
type DBUsermeta ¶ added in v0.0.11
type DBUsermeta struct {
UmetaID uint64 `db:"umeta_id"`
UserID uint64 `db:"user_id"`
MetaKey string `db:"meta_key"`
MetaValue string `db:"meta_value"`
}
func (DBUsermeta) SelectField ¶ added in v0.0.11
func (DBUsermeta) SelectField() []string
type DBUsers ¶ added in v0.0.5
type DBUsers struct {
ID uint64 `db:"ID"`
UserLogin string `db:"user_login"`
UserPhone string `db:"user_phone"`
UserPass string `db:"user_pass"`
UserNicename string `db:"user_nicename"`
UserEmail string `db:"user_email"`
UserURL string `db:"user_url"`
UserRegistered time.Time `db:"user_registered"`
UserActivationKey string `db:"user_activation_key"`
UserStatus UserStatus `db:"user_status"` // TODO
DisplayName string `db:"display_name"`
Deleted int `db:"deleted"`
// 增加微信信息字段
// @since 0.0.4
Openid string `db:"openid"`
WechatHeadImgURL string `db:"wechat_head_img_url"`
Sex int `db:"sex"` // 0 未知 1 男 2 女
Number string `db:"number"` // 用户外码
// @since 0.0.9 增加积分字段
Credits int64 `db:"credits"` // 积分
}
DBUsers 用户表 @since 0.0.4 @since 0.0.9 增加积分字段
func (DBUsers) SelectField ¶ added in v0.0.6
type Label ¶
type Label struct {
ID uint64 `json:"id" gorm:"column:term_taxonomy_id"`
Name string `json:"name" gorm:"column:name"`
Slug string `json:"slug" gorm:"slug"`
Taxonomy string `json:"taxonomy" gorm:"column:taxonomy"`
Description string `json:"description" gorm:"column:description"`
}
Label 状态标记 对应底层是 Term @since 0.0.1
type LogsLogType ¶ added in v0.0.5
type LogsLogType string
LogsLogType 日志类型 @since 0.0.4
const ( // ENUM('router', 'model', 'bind', 'normalize') LogsLogTypeRouter LogsLogType = "router" LogsLogTypeModel LogsLogType = "model" LogsLogTypeNormalize LogsLogType = "LogsLogType" )
LogsLogType 日志类型 @since 0.0.4
func (LogsLogType) String ¶ added in v0.0.5
func (l LogsLogType) String() string
LogsLogType 日志类型 @since 0.0.4
type NavMenu ¶
type NavMenu struct {
}
NavMenu 常用字段结构体 @since 0.0.1
func GetNavMenuByTermID ¶
GetNavMenuByTermID 通过 term_id 获取菜单信息 @since 0.0.1
type OptionNamePrefix ¶ added in v0.0.5
type OptionNamePrefix string
OptionNamePrefix 配置表 name 前缀 @since 0.0.4
const ( // WechatOption 微信前缀 WechatOption OptionNamePrefix = "wechat_" )
func (OptionNamePrefix) String ¶ added in v0.0.5
func (p OptionNamePrefix) String() string
type Post ¶
type Post struct {
ID uint64 `json:"ID" gorm:"primary_key;column:ID"` // ID
Author uint64 `json:"author" gorm:"column:post_author"` // post_author
Date time.Time `json:"date" gorm:"column:post_date"` // post_date
DateGmt time.Time `json:"dateGMT" gorm:"column:post_date_gmt"` // post_date_gmt
Content string `json:"content" gorm:"column:post_content"` // post_content
Title string `json:"title" gorm:"column:post_title"` // post_title
Excerpt string `json:"excerpt" gorm:"column:post_excerpt"` // post_excerpt
Status string `json:"status" gorm:"column:post_status"` // post_status
CommentStatus string `json:"commentStatus"` // comment_status
Password string `json:"password" gorm:"column:post_password"` // post_password
Name string `json:"name" gorm:"column:post_name"` // post_name
Modified time.Time `json:"modified" gorm:"column:post_modified"` // post_modified
ModifiedGmt time.Time `json:"modifiedGMT" gorm:"column:post_modified_gmt"` // post_modified_gmt
Parent uint64 `json:"parent" gorm:"column:post_parent"` // post_parent
Type string `json:"type" gorm:"column:post_type"` // post_type
CommentCount int64 `json:"comment_count"` // comment_count
IsTOP bool `json:"is_top"` // @since 0.0.12 增加置顶标记
Thumbnail string `json:"thumbnail"` // @since 0.0.12 增加封面图标记
Postmetas []*DBPostmeta
Categorys []*Category
Labels []*Label
}
Post 文章常用结构体 修改过 DBpost @since 0.0.1
type SubMenu ¶
type SubMenu struct {
ID uint64
PostTitle string
// EnName string
Parent int64
MenuOrder int
URL string
SubMenus []*SubMenu `json:"sub_menus"` // sub_menus
}
SubMenu 子菜单循环的结构体 @since 0.0.1
type SubMenus ¶
type SubMenus []*SubMenu
SubMenus sort
type Taxonomy ¶ added in v0.0.12
type Taxonomy struct {
TermID uint64
Name string
TermTaxonomyID uint64
Taxonomy string
Parent uint64
Count int64
Order int
}
@since 0.0.12 @since 0.0.18 增加 order 字段
type TermRelationship ¶
type TermRelationship struct {
ObjectID uint64 `json:"object_id"` // object_id
TermTaxonomyID uint64 `json:"term_taxonomy_id"` // term_taxonomy_id
TermOrder int `json:"term_order"` // term_order
// *wpsapi.TermRelationship 这里惊天大 BUG TermRelationship{} 会出现 nil 而不能绑定
Term *wpsapi.Term
}
TermRelationship 分类 修改过 DBTermRelationship @since 0.0.1
type UserStatus ¶ added in v0.0.5
type UserStatus int
UserStatus users user_status 用来存储用户状态
const ( // UserStatusWechatFollow 微信关注 UserStatusWechatFollow UserStatus = 0 // UserStatusWechatRegister 微信注册 UserStatusWechatRegister UserStatus = 1 // UserStatusSystemRegister 系统注册 UserStatusSystemRegister UserStatus = 2 )