2024-11-07 10:09:13 +00:00
|
|
|
// 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 dao
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
"gorm.io/gorm/clause"
|
|
|
|
"gorm.io/gorm/schema"
|
|
|
|
|
|
|
|
"gorm.io/gen"
|
|
|
|
"gorm.io/gen/field"
|
|
|
|
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
|
|
|
|
"leafdev.top/Ecosystem/recommender/internal/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.NewUint(tableName, "id")
|
|
|
|
_post.CreatedAt = field.NewTime(tableName, "created_at")
|
|
|
|
_post.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
|
|
_post.Title = field.NewString(tableName, "title")
|
|
|
|
_post.Content = field.NewString(tableName, "content")
|
|
|
|
_post.TargetId = field.NewString(tableName, "target_id")
|
2024-11-07 18:25:15 +00:00
|
|
|
_post.ApplicationId = field.NewUint(tableName, "application_id")
|
|
|
|
_post.CategoryId = field.NewUint(tableName, "category_id")
|
2024-11-07 10:09:13 +00:00
|
|
|
_post.Processed = field.NewBool(tableName, "processed")
|
2024-11-09 19:49:53 +00:00
|
|
|
_post.Vectorized = field.NewBool(tableName, "vectorized")
|
2024-11-07 18:25:15 +00:00
|
|
|
_post.Application = postBelongsToApplication{
|
|
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
|
|
|
|
RelationField: field.NewRelation("Application", "entity.Application"),
|
|
|
|
}
|
|
|
|
|
|
|
|
_post.Category = postBelongsToCategory{
|
|
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
|
|
|
|
RelationField: field.NewRelation("Category", "entity.Category"),
|
|
|
|
Application: struct {
|
|
|
|
field.RelationField
|
|
|
|
}{
|
|
|
|
RelationField: field.NewRelation("Category.Application", "entity.Application"),
|
|
|
|
},
|
|
|
|
}
|
2024-11-07 10:09:13 +00:00
|
|
|
|
|
|
|
_post.fillFieldMap()
|
|
|
|
|
|
|
|
return _post
|
|
|
|
}
|
|
|
|
|
|
|
|
type post struct {
|
|
|
|
postDo
|
|
|
|
|
2024-11-07 18:25:15 +00:00
|
|
|
ALL field.Asterisk
|
|
|
|
Id field.Uint
|
|
|
|
CreatedAt field.Time
|
|
|
|
UpdatedAt field.Time
|
|
|
|
Title field.String
|
|
|
|
Content field.String
|
|
|
|
TargetId field.String
|
|
|
|
ApplicationId field.Uint
|
|
|
|
CategoryId field.Uint
|
|
|
|
Processed field.Bool
|
2024-11-09 19:49:53 +00:00
|
|
|
Vectorized field.Bool
|
2024-11-07 18:25:15 +00:00
|
|
|
Application postBelongsToApplication
|
|
|
|
|
|
|
|
Category postBelongsToCategory
|
2024-11-07 10:09:13 +00:00
|
|
|
|
|
|
|
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.NewUint(table, "id")
|
|
|
|
p.CreatedAt = field.NewTime(table, "created_at")
|
|
|
|
p.UpdatedAt = field.NewTime(table, "updated_at")
|
|
|
|
p.Title = field.NewString(table, "title")
|
|
|
|
p.Content = field.NewString(table, "content")
|
|
|
|
p.TargetId = field.NewString(table, "target_id")
|
2024-11-07 18:25:15 +00:00
|
|
|
p.ApplicationId = field.NewUint(table, "application_id")
|
|
|
|
p.CategoryId = field.NewUint(table, "category_id")
|
2024-11-07 10:09:13 +00:00
|
|
|
p.Processed = field.NewBool(table, "processed")
|
2024-11-09 19:49:53 +00:00
|
|
|
p.Vectorized = field.NewBool(table, "vectorized")
|
2024-11-07 10:09:13 +00:00
|
|
|
|
|
|
|
p.fillFieldMap()
|
|
|
|
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
2024-11-09 19:49:53 +00:00
|
|
|
p.fieldMap = make(map[string]field.Expr, 12)
|
2024-11-07 10:09:13 +00:00
|
|
|
p.fieldMap["id"] = p.Id
|
|
|
|
p.fieldMap["created_at"] = p.CreatedAt
|
|
|
|
p.fieldMap["updated_at"] = p.UpdatedAt
|
|
|
|
p.fieldMap["title"] = p.Title
|
|
|
|
p.fieldMap["content"] = p.Content
|
|
|
|
p.fieldMap["target_id"] = p.TargetId
|
2024-11-07 18:25:15 +00:00
|
|
|
p.fieldMap["application_id"] = p.ApplicationId
|
|
|
|
p.fieldMap["category_id"] = p.CategoryId
|
2024-11-07 10:09:13 +00:00
|
|
|
p.fieldMap["processed"] = p.Processed
|
2024-11-09 19:49:53 +00:00
|
|
|
p.fieldMap["vectorized"] = p.Vectorized
|
2024-11-07 18:25:15 +00:00
|
|
|
|
2024-11-07 10:09:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-11-07 18:25:15 +00:00
|
|
|
type postBelongsToApplication struct {
|
|
|
|
db *gorm.DB
|
|
|
|
|
|
|
|
field.RelationField
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplication) Where(conds ...field.Expr) *postBelongsToApplication {
|
|
|
|
if len(conds) == 0 {
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
|
|
for _, cond := range conds {
|
|
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
|
|
}
|
|
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplication) WithContext(ctx context.Context) *postBelongsToApplication {
|
|
|
|
a.db = a.db.WithContext(ctx)
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplication) Session(session *gorm.Session) *postBelongsToApplication {
|
|
|
|
a.db = a.db.Session(session)
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplication) Model(m *entity.Post) *postBelongsToApplicationTx {
|
|
|
|
return &postBelongsToApplicationTx{a.db.Model(m).Association(a.Name())}
|
|
|
|
}
|
|
|
|
|
|
|
|
type postBelongsToApplicationTx struct{ tx *gorm.Association }
|
|
|
|
|
|
|
|
func (a postBelongsToApplicationTx) Find() (result *entity.Application, err error) {
|
|
|
|
return result, a.tx.Find(&result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplicationTx) Append(values ...*entity.Application) (err error) {
|
|
|
|
targetValues := make([]interface{}, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
targetValues[i] = v
|
|
|
|
}
|
|
|
|
return a.tx.Append(targetValues...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplicationTx) Replace(values ...*entity.Application) (err error) {
|
|
|
|
targetValues := make([]interface{}, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
targetValues[i] = v
|
|
|
|
}
|
|
|
|
return a.tx.Replace(targetValues...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplicationTx) Delete(values ...*entity.Application) (err error) {
|
|
|
|
targetValues := make([]interface{}, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
targetValues[i] = v
|
|
|
|
}
|
|
|
|
return a.tx.Delete(targetValues...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplicationTx) Clear() error {
|
|
|
|
return a.tx.Clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToApplicationTx) Count() int64 {
|
|
|
|
return a.tx.Count()
|
|
|
|
}
|
|
|
|
|
|
|
|
type postBelongsToCategory struct {
|
|
|
|
db *gorm.DB
|
|
|
|
|
|
|
|
field.RelationField
|
|
|
|
|
|
|
|
Application struct {
|
|
|
|
field.RelationField
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategory) Where(conds ...field.Expr) *postBelongsToCategory {
|
|
|
|
if len(conds) == 0 {
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
|
|
for _, cond := range conds {
|
|
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
|
|
}
|
|
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategory) WithContext(ctx context.Context) *postBelongsToCategory {
|
|
|
|
a.db = a.db.WithContext(ctx)
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategory) Session(session *gorm.Session) *postBelongsToCategory {
|
|
|
|
a.db = a.db.Session(session)
|
|
|
|
return &a
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategory) Model(m *entity.Post) *postBelongsToCategoryTx {
|
|
|
|
return &postBelongsToCategoryTx{a.db.Model(m).Association(a.Name())}
|
|
|
|
}
|
|
|
|
|
|
|
|
type postBelongsToCategoryTx struct{ tx *gorm.Association }
|
|
|
|
|
|
|
|
func (a postBelongsToCategoryTx) Find() (result *entity.Category, err error) {
|
|
|
|
return result, a.tx.Find(&result)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategoryTx) Append(values ...*entity.Category) (err error) {
|
|
|
|
targetValues := make([]interface{}, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
targetValues[i] = v
|
|
|
|
}
|
|
|
|
return a.tx.Append(targetValues...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategoryTx) Replace(values ...*entity.Category) (err error) {
|
|
|
|
targetValues := make([]interface{}, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
targetValues[i] = v
|
|
|
|
}
|
|
|
|
return a.tx.Replace(targetValues...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategoryTx) Delete(values ...*entity.Category) (err error) {
|
|
|
|
targetValues := make([]interface{}, len(values))
|
|
|
|
for i, v := range values {
|
|
|
|
targetValues[i] = v
|
|
|
|
}
|
|
|
|
return a.tx.Delete(targetValues...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategoryTx) Clear() error {
|
|
|
|
return a.tx.Clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (a postBelongsToCategoryTx) Count() int64 {
|
|
|
|
return a.tx.Count()
|
|
|
|
}
|
|
|
|
|
2024-11-07 10:09:13 +00:00
|
|
|
type postDo struct{ gen.DO }
|
|
|
|
|
|
|
|
type IPostDo interface {
|
|
|
|
gen.SubQuery
|
|
|
|
Debug() IPostDo
|
|
|
|
WithContext(ctx context.Context) IPostDo
|
|
|
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
|
|
ReplaceDB(db *gorm.DB)
|
|
|
|
ReadDB() IPostDo
|
|
|
|
WriteDB() IPostDo
|
|
|
|
As(alias string) gen.Dao
|
|
|
|
Session(config *gorm.Session) IPostDo
|
|
|
|
Columns(cols ...field.Expr) gen.Columns
|
|
|
|
Clauses(conds ...clause.Expression) IPostDo
|
|
|
|
Not(conds ...gen.Condition) IPostDo
|
|
|
|
Or(conds ...gen.Condition) IPostDo
|
|
|
|
Select(conds ...field.Expr) IPostDo
|
|
|
|
Where(conds ...gen.Condition) IPostDo
|
|
|
|
Order(conds ...field.Expr) IPostDo
|
|
|
|
Distinct(cols ...field.Expr) IPostDo
|
|
|
|
Omit(cols ...field.Expr) IPostDo
|
|
|
|
Join(table schema.Tabler, on ...field.Expr) IPostDo
|
|
|
|
LeftJoin(table schema.Tabler, on ...field.Expr) IPostDo
|
|
|
|
RightJoin(table schema.Tabler, on ...field.Expr) IPostDo
|
|
|
|
Group(cols ...field.Expr) IPostDo
|
|
|
|
Having(conds ...gen.Condition) IPostDo
|
|
|
|
Limit(limit int) IPostDo
|
|
|
|
Offset(offset int) IPostDo
|
|
|
|
Count() (count int64, err error)
|
|
|
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IPostDo
|
|
|
|
Unscoped() IPostDo
|
|
|
|
Create(values ...*entity.Post) error
|
|
|
|
CreateInBatches(values []*entity.Post, batchSize int) error
|
|
|
|
Save(values ...*entity.Post) error
|
|
|
|
First() (*entity.Post, error)
|
|
|
|
Take() (*entity.Post, error)
|
|
|
|
Last() (*entity.Post, error)
|
|
|
|
Find() ([]*entity.Post, error)
|
|
|
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Post, err error)
|
|
|
|
FindInBatches(result *[]*entity.Post, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
|
|
Pluck(column field.Expr, dest interface{}) error
|
|
|
|
Delete(...*entity.Post) (info gen.ResultInfo, err error)
|
|
|
|
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
|
|
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
|
|
Updates(value interface{}) (info gen.ResultInfo, err error)
|
|
|
|
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
|
|
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
|
|
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
|
|
|
UpdateFrom(q gen.SubQuery) gen.Dao
|
|
|
|
Attrs(attrs ...field.AssignExpr) IPostDo
|
|
|
|
Assign(attrs ...field.AssignExpr) IPostDo
|
|
|
|
Joins(fields ...field.RelationField) IPostDo
|
|
|
|
Preload(fields ...field.RelationField) IPostDo
|
|
|
|
FirstOrInit() (*entity.Post, error)
|
|
|
|
FirstOrCreate() (*entity.Post, error)
|
|
|
|
FindByPage(offset int, limit int) (result []*entity.Post, count int64, err error)
|
|
|
|
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
|
|
|
Scan(result interface{}) (err error)
|
|
|
|
Returning(value interface{}, columns ...string) IPostDo
|
|
|
|
UnderlyingDB() *gorm.DB
|
|
|
|
schema.Tabler
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Debug() IPostDo {
|
|
|
|
return p.withDO(p.DO.Debug())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) WithContext(ctx context.Context) IPostDo {
|
|
|
|
return p.withDO(p.DO.WithContext(ctx))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) ReadDB() IPostDo {
|
|
|
|
return p.Clauses(dbresolver.Read)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) WriteDB() IPostDo {
|
|
|
|
return p.Clauses(dbresolver.Write)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Session(config *gorm.Session) IPostDo {
|
|
|
|
return p.withDO(p.DO.Session(config))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Clauses(conds ...clause.Expression) IPostDo {
|
|
|
|
return p.withDO(p.DO.Clauses(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Returning(value interface{}, columns ...string) IPostDo {
|
|
|
|
return p.withDO(p.DO.Returning(value, columns...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Not(conds ...gen.Condition) IPostDo {
|
|
|
|
return p.withDO(p.DO.Not(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Or(conds ...gen.Condition) IPostDo {
|
|
|
|
return p.withDO(p.DO.Or(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Select(conds ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Select(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Where(conds ...gen.Condition) IPostDo {
|
|
|
|
return p.withDO(p.DO.Where(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Order(conds ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Order(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Distinct(cols ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Distinct(cols...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Omit(cols ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Omit(cols...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Join(table schema.Tabler, on ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Join(table, on...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) LeftJoin(table schema.Tabler, on ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.LeftJoin(table, on...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) RightJoin(table schema.Tabler, on ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.RightJoin(table, on...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Group(cols ...field.Expr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Group(cols...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Having(conds ...gen.Condition) IPostDo {
|
|
|
|
return p.withDO(p.DO.Having(conds...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Limit(limit int) IPostDo {
|
|
|
|
return p.withDO(p.DO.Limit(limit))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Offset(offset int) IPostDo {
|
|
|
|
return p.withDO(p.DO.Offset(offset))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IPostDo {
|
|
|
|
return p.withDO(p.DO.Scopes(funcs...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Unscoped() IPostDo {
|
|
|
|
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) IPostDo {
|
|
|
|
return p.withDO(p.DO.Attrs(attrs...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Assign(attrs ...field.AssignExpr) IPostDo {
|
|
|
|
return p.withDO(p.DO.Assign(attrs...))
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Joins(fields ...field.RelationField) IPostDo {
|
|
|
|
for _, _f := range fields {
|
|
|
|
p = *p.withDO(p.DO.Joins(_f))
|
|
|
|
}
|
|
|
|
return &p
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p postDo) Preload(fields ...field.RelationField) IPostDo {
|
|
|
|
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
|
|
|
|
}
|