Documentation
¶
Overview ¶
Package model 尝试缓存友好的编写
log db @since 0.0.4
定义框架需要支持的基础数据库类型字段和一些数据库连接句柄等相关处理 做过一些业务的new方法 后面应该补全
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 ExecSql(tx *sql.Tx, builder interface{}) (sql.Result, 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 DBOrderGoods
- type DBOrderInfo
- type DBPost
- type DBPostmeta
- type DBTaxonomyMeta
- 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"
DB 数据库接口 @since 0.0.1
var ErrEmptyResult = scanner.ErrEmptyResult
var Insert insert
Insert 插入基础数据
var Null null
Null 用于安全获取结构体零值 @since 0.0.1
Functions ¶
func EditCategory ¶
EditCategory 编辑分类 @since 0.0.1
func ExecSql ¶ added in v0.0.22
通用的执行sql语句 @since 0.0.22 自动记录日志 自动生成sql 自动调用 出错自动回滚
func GetDBPostmetas ¶
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 ¶
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 SetOption ¶
SetOption 设置网站 option @since 0.0.1
func UpdateMenuTree ¶
UpdateMenuTree 更新菜单顺序 @since 0.0.1
func WriteLogToDB ¶
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
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"` // 创建时间
}
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 ¶
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
type DBCouponLog ¶
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 ¶
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 ¶
func (DBCreditLog) SelectField() []string
type DBGoods ¶
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 DBLogs ¶
DBLogs 日志表 @since 0.0.4 尝试添加日志到 mysql 8 数据库中,使用 json 的新特性
type DBOrderGoods ¶ added in v0.0.22
@since 0.0.22 订单商品
type DBOrderInfo ¶ added in v0.0.22
type DBOrderInfo struct {
OrderID uint64 `db:"order_id"`
OrderSN string `db:"order_sn"`
Mobile string `db:"mobile"`
GoodsAmount float64 `db:"goods_amount"`
}
@since 0.0.22 订单头表
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
type DBPostmeta ¶
DBPostmeta 文章属性 @since 0.0.1 @since 0.0.4 重命名 Postmeta -> DBPostmeta
type DBTaxonomyMeta ¶ added in v0.0.25
type DBTaxonomyMeta struct {
MetaID uint64 `db:"meta_id"`
TermTaxonomyID uint64 `db:"term_taxonomy_id"`
MetaKey string `db:"meta_key"`
MetaValue string `db:"meta_value"`
}
func (DBTaxonomyMeta) SelectField ¶ added in v0.0.25
func (DBTaxonomyMeta) SelectField() []string
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 ¶
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 ¶
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 ¶
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 ¶
func (DBUsermeta) SelectField() []string
type DBUsers ¶
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 增加积分字段
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 ¶
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
type OptionNamePrefix ¶
type OptionNamePrefix string
OptionNamePrefix 配置表 name 前缀 @since 0.0.4
const ( // WechatOption 微信前缀 WechatOption OptionNamePrefix = "wechat_" )
func (OptionNamePrefix) String ¶
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
func (SubMenus) Less ¶
Less 方法报告索引i的元素是否比索引j的元素小 @since 0.0.1
type Tag ¶
Tag 标签结构体 @since 0.0.1
type Taxonomy ¶
type Taxonomy struct {
TermID uint64
Name string
TermTaxonomyID uint64
Taxonomy string
Parent uint64 // TODO 改成 ParentTermTaxonomyID
Count int64
Order int
SubTaxonomy *[]Taxonomy
TaxonomyMeta *map[string]DBTaxonomyMeta // TODO 待查询出结果
}
@since 0.0.12 @since 0.0.18 增加 order 字段 @since 0.0.22 增加 SubTaxonomy 字段 @since 0.0.25 将 TaxonomyMeta 改为 map 结构
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 Tree ¶
Tree 菜单排序及上下级关系结构体 @since 0.0.1
type UserStatus ¶
type UserStatus int
UserStatus users user_status 用来存储用户状态
const ( // UserStatusWechatFollow 微信关注 UserStatusWechatFollow UserStatus = 0 // UserStatusWechatRegister 微信注册 UserStatusWechatRegister UserStatus = 1 // UserStatusSystemRegister 系统注册 UserStatusSystemRegister UserStatus = 2 )
Source Files
¶
- cache.go
- create.go
- insert.go
- log_db.go
- m_category.go
- m_enum.go
- m_goods.go
- m_menu.go
- m_option.go
- m_shop.go
- m_struct.go
- model.go
- null_struct.go