mirror of https://github.com/go-sonic/sonic.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
412 lines
11 KiB
Go
412 lines
11 KiB
Go
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
// Code generated by gorm.io/gen. DO NOT EDIT.
|
|
|
|
package dal
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"github.com/go-sonic/sonic/model/entity"
|
|
)
|
|
|
|
func newPost(db *gorm.DB, opts ...gen.DOOption) post {
|
|
_post := post{}
|
|
|
|
_post.postDo.UseDB(db, opts...)
|
|
_post.postDo.UseModel(&entity.Post{})
|
|
|
|
tableName := _post.postDo.TableName()
|
|
_post.ALL = field.NewAsterisk(tableName)
|
|
_post.ID = field.NewInt32(tableName, "id")
|
|
_post.Type = field.NewField(tableName, "type")
|
|
_post.CreateTime = field.NewTime(tableName, "create_time")
|
|
_post.UpdateTime = field.NewTime(tableName, "update_time")
|
|
_post.DisallowComment = field.NewBool(tableName, "disallow_comment")
|
|
_post.EditTime = field.NewTime(tableName, "edit_time")
|
|
_post.EditorType = field.NewField(tableName, "editor_type")
|
|
_post.FormatContent = field.NewString(tableName, "format_content")
|
|
_post.Likes = field.NewInt64(tableName, "likes")
|
|
_post.MetaDescription = field.NewString(tableName, "meta_description")
|
|
_post.MetaKeywords = field.NewString(tableName, "meta_keywords")
|
|
_post.OriginalContent = field.NewString(tableName, "original_content")
|
|
_post.Password = field.NewString(tableName, "password")
|
|
_post.Slug = field.NewString(tableName, "slug")
|
|
_post.Status = field.NewField(tableName, "status")
|
|
_post.Summary = field.NewString(tableName, "summary")
|
|
_post.Template = field.NewString(tableName, "template")
|
|
_post.Thumbnail = field.NewString(tableName, "thumbnail")
|
|
_post.Title = field.NewString(tableName, "title")
|
|
_post.TopPriority = field.NewInt32(tableName, "top_priority")
|
|
_post.Visits = field.NewInt64(tableName, "visits")
|
|
_post.WordCount = field.NewInt64(tableName, "word_count")
|
|
|
|
_post.fillFieldMap()
|
|
|
|
return _post
|
|
}
|
|
|
|
type post struct {
|
|
postDo postDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
Type field.Field
|
|
CreateTime field.Time
|
|
UpdateTime field.Time
|
|
DisallowComment field.Bool
|
|
EditTime field.Time
|
|
EditorType field.Field
|
|
FormatContent field.String
|
|
Likes field.Int64
|
|
MetaDescription field.String
|
|
MetaKeywords field.String
|
|
OriginalContent field.String
|
|
Password field.String
|
|
Slug field.String
|
|
Status field.Field
|
|
Summary field.String
|
|
Template field.String
|
|
Thumbnail field.String
|
|
Title field.String
|
|
TopPriority field.Int32
|
|
Visits field.Int64
|
|
WordCount field.Int64
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (p post) Table(newTableName string) *post {
|
|
p.postDo.UseTable(newTableName)
|
|
return p.updateTableName(newTableName)
|
|
}
|
|
|
|
func (p post) As(alias string) *post {
|
|
p.postDo.DO = *(p.postDo.As(alias).(*gen.DO))
|
|
return p.updateTableName(alias)
|
|
}
|
|
|
|
func (p *post) updateTableName(table string) *post {
|
|
p.ALL = field.NewAsterisk(table)
|
|
p.ID = field.NewInt32(table, "id")
|
|
p.Type = field.NewField(table, "type")
|
|
p.CreateTime = field.NewTime(table, "create_time")
|
|
p.UpdateTime = field.NewTime(table, "update_time")
|
|
p.DisallowComment = field.NewBool(table, "disallow_comment")
|
|
p.EditTime = field.NewTime(table, "edit_time")
|
|
p.EditorType = field.NewField(table, "editor_type")
|
|
p.FormatContent = field.NewString(table, "format_content")
|
|
p.Likes = field.NewInt64(table, "likes")
|
|
p.MetaDescription = field.NewString(table, "meta_description")
|
|
p.MetaKeywords = field.NewString(table, "meta_keywords")
|
|
p.OriginalContent = field.NewString(table, "original_content")
|
|
p.Password = field.NewString(table, "password")
|
|
p.Slug = field.NewString(table, "slug")
|
|
p.Status = field.NewField(table, "status")
|
|
p.Summary = field.NewString(table, "summary")
|
|
p.Template = field.NewString(table, "template")
|
|
p.Thumbnail = field.NewString(table, "thumbnail")
|
|
p.Title = field.NewString(table, "title")
|
|
p.TopPriority = field.NewInt32(table, "top_priority")
|
|
p.Visits = field.NewInt64(table, "visits")
|
|
p.WordCount = field.NewInt64(table, "word_count")
|
|
|
|
p.fillFieldMap()
|
|
|
|
return p
|
|
}
|
|
|
|
func (p *post) WithContext(ctx context.Context) *postDo { return p.postDo.WithContext(ctx) }
|
|
|
|
func (p post) TableName() string { return p.postDo.TableName() }
|
|
|
|
func (p post) Alias() string { return p.postDo.Alias() }
|
|
|
|
func (p *post) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := p.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (p *post) fillFieldMap() {
|
|
p.fieldMap = make(map[string]field.Expr, 22)
|
|
p.fieldMap["id"] = p.ID
|
|
p.fieldMap["type"] = p.Type
|
|
p.fieldMap["create_time"] = p.CreateTime
|
|
p.fieldMap["update_time"] = p.UpdateTime
|
|
p.fieldMap["disallow_comment"] = p.DisallowComment
|
|
p.fieldMap["edit_time"] = p.EditTime
|
|
p.fieldMap["editor_type"] = p.EditorType
|
|
p.fieldMap["format_content"] = p.FormatContent
|
|
p.fieldMap["likes"] = p.Likes
|
|
p.fieldMap["meta_description"] = p.MetaDescription
|
|
p.fieldMap["meta_keywords"] = p.MetaKeywords
|
|
p.fieldMap["original_content"] = p.OriginalContent
|
|
p.fieldMap["password"] = p.Password
|
|
p.fieldMap["slug"] = p.Slug
|
|
p.fieldMap["status"] = p.Status
|
|
p.fieldMap["summary"] = p.Summary
|
|
p.fieldMap["template"] = p.Template
|
|
p.fieldMap["thumbnail"] = p.Thumbnail
|
|
p.fieldMap["title"] = p.Title
|
|
p.fieldMap["top_priority"] = p.TopPriority
|
|
p.fieldMap["visits"] = p.Visits
|
|
p.fieldMap["word_count"] = p.WordCount
|
|
}
|
|
|
|
func (p post) clone(db *gorm.DB) post {
|
|
p.postDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return p
|
|
}
|
|
|
|
func (p post) replaceDB(db *gorm.DB) post {
|
|
p.postDo.ReplaceDB(db)
|
|
return p
|
|
}
|
|
|
|
type postDo struct{ gen.DO }
|
|
|
|
func (p postDo) Debug() *postDo {
|
|
return p.withDO(p.DO.Debug())
|
|
}
|
|
|
|
func (p postDo) WithContext(ctx context.Context) *postDo {
|
|
return p.withDO(p.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (p postDo) ReadDB() *postDo {
|
|
return p.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (p postDo) WriteDB() *postDo {
|
|
return p.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (p postDo) Session(config *gorm.Session) *postDo {
|
|
return p.withDO(p.DO.Session(config))
|
|
}
|
|
|
|
func (p postDo) Clauses(conds ...clause.Expression) *postDo {
|
|
return p.withDO(p.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (p postDo) Returning(value interface{}, columns ...string) *postDo {
|
|
return p.withDO(p.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (p postDo) Not(conds ...gen.Condition) *postDo {
|
|
return p.withDO(p.DO.Not(conds...))
|
|
}
|
|
|
|
func (p postDo) Or(conds ...gen.Condition) *postDo {
|
|
return p.withDO(p.DO.Or(conds...))
|
|
}
|
|
|
|
func (p postDo) Select(conds ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.Select(conds...))
|
|
}
|
|
|
|
func (p postDo) Where(conds ...gen.Condition) *postDo {
|
|
return p.withDO(p.DO.Where(conds...))
|
|
}
|
|
|
|
func (p postDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *postDo {
|
|
return p.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
|
|
}
|
|
|
|
func (p postDo) Order(conds ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.Order(conds...))
|
|
}
|
|
|
|
func (p postDo) Distinct(cols ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (p postDo) Omit(cols ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.Omit(cols...))
|
|
}
|
|
|
|
func (p postDo) Join(table schema.Tabler, on ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.Join(table, on...))
|
|
}
|
|
|
|
func (p postDo) LeftJoin(table schema.Tabler, on ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (p postDo) RightJoin(table schema.Tabler, on ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (p postDo) Group(cols ...field.Expr) *postDo {
|
|
return p.withDO(p.DO.Group(cols...))
|
|
}
|
|
|
|
func (p postDo) Having(conds ...gen.Condition) *postDo {
|
|
return p.withDO(p.DO.Having(conds...))
|
|
}
|
|
|
|
func (p postDo) Limit(limit int) *postDo {
|
|
return p.withDO(p.DO.Limit(limit))
|
|
}
|
|
|
|
func (p postDo) Offset(offset int) *postDo {
|
|
return p.withDO(p.DO.Offset(offset))
|
|
}
|
|
|
|
func (p postDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *postDo {
|
|
return p.withDO(p.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (p postDo) Unscoped() *postDo {
|
|
return p.withDO(p.DO.Unscoped())
|
|
}
|
|
|
|
func (p postDo) Create(values ...*entity.Post) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Create(values)
|
|
}
|
|
|
|
func (p postDo) CreateInBatches(values []*entity.Post, batchSize int) error {
|
|
return p.DO.CreateInBatches(values, batchSize)
|
|
}
|
|
|
|
// Save : !!! underlying implementation is different with GORM
|
|
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
|
func (p postDo) Save(values ...*entity.Post) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Save(values)
|
|
}
|
|
|
|
func (p postDo) First() (*entity.Post, error) {
|
|
if result, err := p.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Post), nil
|
|
}
|
|
}
|
|
|
|
func (p postDo) Take() (*entity.Post, error) {
|
|
if result, err := p.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Post), nil
|
|
}
|
|
}
|
|
|
|
func (p postDo) Last() (*entity.Post, error) {
|
|
if result, err := p.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Post), nil
|
|
}
|
|
}
|
|
|
|
func (p postDo) Find() ([]*entity.Post, error) {
|
|
result, err := p.DO.Find()
|
|
return result.([]*entity.Post), err
|
|
}
|
|
|
|
func (p postDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Post, err error) {
|
|
buf := make([]*entity.Post, 0, batchSize)
|
|
err = p.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
|
defer func() { results = append(results, buf...) }()
|
|
return fc(tx, batch)
|
|
})
|
|
return results, err
|
|
}
|
|
|
|
func (p postDo) FindInBatches(result *[]*entity.Post, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return p.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (p postDo) Attrs(attrs ...field.AssignExpr) *postDo {
|
|
return p.withDO(p.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (p postDo) Assign(attrs ...field.AssignExpr) *postDo {
|
|
return p.withDO(p.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (p postDo) Joins(fields ...field.RelationField) *postDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Joins(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p postDo) Preload(fields ...field.RelationField) *postDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Preload(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p postDo) FirstOrInit() (*entity.Post, error) {
|
|
if result, err := p.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Post), nil
|
|
}
|
|
}
|
|
|
|
func (p postDo) FirstOrCreate() (*entity.Post, error) {
|
|
if result, err := p.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Post), nil
|
|
}
|
|
}
|
|
|
|
func (p postDo) FindByPage(offset int, limit int) (result []*entity.Post, count int64, err error) {
|
|
result, err = p.Offset(offset).Limit(limit).Find()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
if size := len(result); 0 < limit && 0 < size && size < limit {
|
|
count = int64(size + offset)
|
|
return
|
|
}
|
|
|
|
count, err = p.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (p postDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = p.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = p.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (p postDo) Scan(result interface{}) (err error) {
|
|
return p.DO.Scan(result)
|
|
}
|
|
|
|
func (p postDo) Delete(models ...*entity.Post) (result gen.ResultInfo, err error) {
|
|
return p.DO.Delete(models)
|
|
}
|
|
|
|
func (p *postDo) withDO(do gen.Dao) *postDo {
|
|
p.DO = *do.(*gen.DO)
|
|
return p
|
|
}
|