Files
platform/web/queries/article.gen.go
2026-06-01 15:46:43 +08:00

443 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 queries
import (
"context"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
"platform/web/models"
)
func newArticle(db *gorm.DB, opts ...gen.DOOption) article {
_article := article{}
_article.articleDo.UseDB(db, opts...)
_article.articleDo.UseModel(&models.Article{})
tableName := _article.articleDo.TableName()
_article.ALL = field.NewAsterisk(tableName)
_article.ID = field.NewInt32(tableName, "id")
_article.CreatedAt = field.NewTime(tableName, "created_at")
_article.UpdatedAt = field.NewTime(tableName, "updated_at")
_article.DeletedAt = field.NewField(tableName, "deleted_at")
_article.GroupID = field.NewInt32(tableName, "group_id")
_article.Title = field.NewString(tableName, "title")
_article.Content = field.NewString(tableName, "content")
_article.Sort = field.NewInt32(tableName, "sort")
_article.Status = field.NewInt(tableName, "status")
_article.Group = articleBelongsToGroup{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("Group", "models.ArticleGroup"),
}
_article.fillFieldMap()
return _article
}
type article struct {
articleDo
ALL field.Asterisk
ID field.Int32
CreatedAt field.Time
UpdatedAt field.Time
DeletedAt field.Field
GroupID field.Int32
Title field.String
Content field.String
Sort field.Int32
Status field.Int
Group articleBelongsToGroup
fieldMap map[string]field.Expr
}
func (a article) Table(newTableName string) *article {
a.articleDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a article) As(alias string) *article {
a.articleDo.DO = *(a.articleDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *article) updateTableName(table string) *article {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.CreatedAt = field.NewTime(table, "created_at")
a.UpdatedAt = field.NewTime(table, "updated_at")
a.DeletedAt = field.NewField(table, "deleted_at")
a.GroupID = field.NewInt32(table, "group_id")
a.Title = field.NewString(table, "title")
a.Content = field.NewString(table, "content")
a.Sort = field.NewInt32(table, "sort")
a.Status = field.NewInt(table, "status")
a.fillFieldMap()
return a
}
func (a *article) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
_f, ok := a.fieldMap[fieldName]
if !ok || _f == nil {
return nil, false
}
_oe, ok := _f.(field.OrderExpr)
return _oe, ok
}
func (a *article) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 10)
a.fieldMap["id"] = a.ID
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
a.fieldMap["deleted_at"] = a.DeletedAt
a.fieldMap["group_id"] = a.GroupID
a.fieldMap["title"] = a.Title
a.fieldMap["content"] = a.Content
a.fieldMap["sort"] = a.Sort
a.fieldMap["status"] = a.Status
}
func (a article) clone(db *gorm.DB) article {
a.articleDo.ReplaceConnPool(db.Statement.ConnPool)
a.Group.db = db.Session(&gorm.Session{Initialized: true})
a.Group.db.Statement.ConnPool = db.Statement.ConnPool
return a
}
func (a article) replaceDB(db *gorm.DB) article {
a.articleDo.ReplaceDB(db)
a.Group.db = db.Session(&gorm.Session{})
return a
}
type articleBelongsToGroup struct {
db *gorm.DB
field.RelationField
}
func (a articleBelongsToGroup) Where(conds ...field.Expr) *articleBelongsToGroup {
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 articleBelongsToGroup) WithContext(ctx context.Context) *articleBelongsToGroup {
a.db = a.db.WithContext(ctx)
return &a
}
func (a articleBelongsToGroup) Session(session *gorm.Session) *articleBelongsToGroup {
a.db = a.db.Session(session)
return &a
}
func (a articleBelongsToGroup) Model(m *models.Article) *articleBelongsToGroupTx {
return &articleBelongsToGroupTx{a.db.Model(m).Association(a.Name())}
}
func (a articleBelongsToGroup) Unscoped() *articleBelongsToGroup {
a.db = a.db.Unscoped()
return &a
}
type articleBelongsToGroupTx struct{ tx *gorm.Association }
func (a articleBelongsToGroupTx) Find() (result *models.ArticleGroup, err error) {
return result, a.tx.Find(&result)
}
func (a articleBelongsToGroupTx) Append(values ...*models.ArticleGroup) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a articleBelongsToGroupTx) Replace(values ...*models.ArticleGroup) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a articleBelongsToGroupTx) Delete(values ...*models.ArticleGroup) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a articleBelongsToGroupTx) Clear() error {
return a.tx.Clear()
}
func (a articleBelongsToGroupTx) Count() int64 {
return a.tx.Count()
}
func (a articleBelongsToGroupTx) Unscoped() *articleBelongsToGroupTx {
a.tx = a.tx.Unscoped()
return &a
}
type articleDo struct{ gen.DO }
func (a articleDo) Debug() *articleDo {
return a.withDO(a.DO.Debug())
}
func (a articleDo) WithContext(ctx context.Context) *articleDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a articleDo) ReadDB() *articleDo {
return a.Clauses(dbresolver.Read)
}
func (a articleDo) WriteDB() *articleDo {
return a.Clauses(dbresolver.Write)
}
func (a articleDo) Session(config *gorm.Session) *articleDo {
return a.withDO(a.DO.Session(config))
}
func (a articleDo) Clauses(conds ...clause.Expression) *articleDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a articleDo) Returning(value interface{}, columns ...string) *articleDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a articleDo) Not(conds ...gen.Condition) *articleDo {
return a.withDO(a.DO.Not(conds...))
}
func (a articleDo) Or(conds ...gen.Condition) *articleDo {
return a.withDO(a.DO.Or(conds...))
}
func (a articleDo) Select(conds ...field.Expr) *articleDo {
return a.withDO(a.DO.Select(conds...))
}
func (a articleDo) Where(conds ...gen.Condition) *articleDo {
return a.withDO(a.DO.Where(conds...))
}
func (a articleDo) Order(conds ...field.Expr) *articleDo {
return a.withDO(a.DO.Order(conds...))
}
func (a articleDo) Distinct(cols ...field.Expr) *articleDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a articleDo) Omit(cols ...field.Expr) *articleDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a articleDo) Join(table schema.Tabler, on ...field.Expr) *articleDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a articleDo) LeftJoin(table schema.Tabler, on ...field.Expr) *articleDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a articleDo) RightJoin(table schema.Tabler, on ...field.Expr) *articleDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a articleDo) Group(cols ...field.Expr) *articleDo {
return a.withDO(a.DO.Group(cols...))
}
func (a articleDo) Having(conds ...gen.Condition) *articleDo {
return a.withDO(a.DO.Having(conds...))
}
func (a articleDo) Limit(limit int) *articleDo {
return a.withDO(a.DO.Limit(limit))
}
func (a articleDo) Offset(offset int) *articleDo {
return a.withDO(a.DO.Offset(offset))
}
func (a articleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *articleDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a articleDo) Unscoped() *articleDo {
return a.withDO(a.DO.Unscoped())
}
func (a articleDo) Create(values ...*models.Article) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a articleDo) CreateInBatches(values []*models.Article, batchSize int) error {
return a.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 (a articleDo) Save(values ...*models.Article) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a articleDo) First() (*models.Article, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.Article), nil
}
}
func (a articleDo) Take() (*models.Article, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.Article), nil
}
}
func (a articleDo) Last() (*models.Article, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.Article), nil
}
}
func (a articleDo) Find() ([]*models.Article, error) {
result, err := a.DO.Find()
return result.([]*models.Article), err
}
func (a articleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Article, err error) {
buf := make([]*models.Article, 0, batchSize)
err = a.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 (a articleDo) FindInBatches(result *[]*models.Article, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a articleDo) Attrs(attrs ...field.AssignExpr) *articleDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a articleDo) Assign(attrs ...field.AssignExpr) *articleDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a articleDo) Joins(fields ...field.RelationField) *articleDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a articleDo) Preload(fields ...field.RelationField) *articleDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a articleDo) FirstOrInit() (*models.Article, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.Article), nil
}
}
func (a articleDo) FirstOrCreate() (*models.Article, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.Article), nil
}
}
func (a articleDo) FindByPage(offset int, limit int) (result []*models.Article, count int64, err error) {
result, err = a.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 = a.Offset(-1).Limit(-1).Count()
return
}
func (a articleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
count, err = a.Count()
if err != nil {
return
}
err = a.Offset(offset).Limit(limit).Scan(result)
return
}
func (a articleDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a articleDo) Delete(models ...*models.Article) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *articleDo) withDO(do gen.Dao) *articleDo {
a.DO = *do.(*gen.DO)
return a
}