Files
platform/web/queries/announcement.gen.go

356 lines
9.7 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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 newAnnouncement(db *gorm.DB, opts ...gen.DOOption) announcement {
_announcement := announcement{}
_announcement.announcementDo.UseDB(db, opts...)
_announcement.announcementDo.UseModel(&models.Announcement{})
tableName := _announcement.announcementDo.TableName()
_announcement.ALL = field.NewAsterisk(tableName)
_announcement.ID = field.NewInt32(tableName, "id")
_announcement.Title = field.NewString(tableName, "title")
_announcement.Content = field.NewString(tableName, "content")
_announcement.Type = field.NewInt32(tableName, "type")
_announcement.Pin = field.NewBool(tableName, "pin")
_announcement.Status = field.NewInt32(tableName, "status")
_announcement.Sort = field.NewInt32(tableName, "sort")
_announcement.CreatedAt = field.NewField(tableName, "created_at")
_announcement.UpdatedAt = field.NewField(tableName, "updated_at")
_announcement.DeletedAt = field.NewField(tableName, "deleted_at")
_announcement.fillFieldMap()
return _announcement
}
type announcement struct {
announcementDo
ALL field.Asterisk
ID field.Int32 // 公告ID
Title field.String // 公告标题
Content field.String // 公告内容
Type field.Int32 // 公告类型1-普通公告
Pin field.Bool // 是否置顶
Status field.Int32 // 公告状态0-禁用1-正常
Sort field.Int32 // 公告排序
CreatedAt field.Field // 创建时间
UpdatedAt field.Field // 更新时间
DeletedAt field.Field // 删除时间
fieldMap map[string]field.Expr
}
func (a announcement) Table(newTableName string) *announcement {
a.announcementDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a announcement) As(alias string) *announcement {
a.announcementDo.DO = *(a.announcementDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *announcement) updateTableName(table string) *announcement {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.Title = field.NewString(table, "title")
a.Content = field.NewString(table, "content")
a.Type = field.NewInt32(table, "type")
a.Pin = field.NewBool(table, "pin")
a.Status = field.NewInt32(table, "status")
a.Sort = field.NewInt32(table, "sort")
a.CreatedAt = field.NewField(table, "created_at")
a.UpdatedAt = field.NewField(table, "updated_at")
a.DeletedAt = field.NewField(table, "deleted_at")
a.fillFieldMap()
return a
}
func (a *announcement) 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 *announcement) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 10)
a.fieldMap["id"] = a.ID
a.fieldMap["title"] = a.Title
a.fieldMap["content"] = a.Content
a.fieldMap["type"] = a.Type
a.fieldMap["pin"] = a.Pin
a.fieldMap["status"] = a.Status
a.fieldMap["sort"] = a.Sort
a.fieldMap["created_at"] = a.CreatedAt
a.fieldMap["updated_at"] = a.UpdatedAt
a.fieldMap["deleted_at"] = a.DeletedAt
}
func (a announcement) clone(db *gorm.DB) announcement {
a.announcementDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a announcement) replaceDB(db *gorm.DB) announcement {
a.announcementDo.ReplaceDB(db)
return a
}
type announcementDo struct{ gen.DO }
func (a announcementDo) Debug() *announcementDo {
return a.withDO(a.DO.Debug())
}
func (a announcementDo) WithContext(ctx context.Context) *announcementDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a announcementDo) ReadDB() *announcementDo {
return a.Clauses(dbresolver.Read)
}
func (a announcementDo) WriteDB() *announcementDo {
return a.Clauses(dbresolver.Write)
}
func (a announcementDo) Session(config *gorm.Session) *announcementDo {
return a.withDO(a.DO.Session(config))
}
func (a announcementDo) Clauses(conds ...clause.Expression) *announcementDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a announcementDo) Returning(value interface{}, columns ...string) *announcementDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a announcementDo) Not(conds ...gen.Condition) *announcementDo {
return a.withDO(a.DO.Not(conds...))
}
func (a announcementDo) Or(conds ...gen.Condition) *announcementDo {
return a.withDO(a.DO.Or(conds...))
}
func (a announcementDo) Select(conds ...field.Expr) *announcementDo {
return a.withDO(a.DO.Select(conds...))
}
func (a announcementDo) Where(conds ...gen.Condition) *announcementDo {
return a.withDO(a.DO.Where(conds...))
}
func (a announcementDo) Order(conds ...field.Expr) *announcementDo {
return a.withDO(a.DO.Order(conds...))
}
func (a announcementDo) Distinct(cols ...field.Expr) *announcementDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a announcementDo) Omit(cols ...field.Expr) *announcementDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a announcementDo) Join(table schema.Tabler, on ...field.Expr) *announcementDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a announcementDo) LeftJoin(table schema.Tabler, on ...field.Expr) *announcementDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a announcementDo) RightJoin(table schema.Tabler, on ...field.Expr) *announcementDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a announcementDo) Group(cols ...field.Expr) *announcementDo {
return a.withDO(a.DO.Group(cols...))
}
func (a announcementDo) Having(conds ...gen.Condition) *announcementDo {
return a.withDO(a.DO.Having(conds...))
}
func (a announcementDo) Limit(limit int) *announcementDo {
return a.withDO(a.DO.Limit(limit))
}
func (a announcementDo) Offset(offset int) *announcementDo {
return a.withDO(a.DO.Offset(offset))
}
func (a announcementDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *announcementDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a announcementDo) Unscoped() *announcementDo {
return a.withDO(a.DO.Unscoped())
}
func (a announcementDo) Create(values ...*models.Announcement) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a announcementDo) CreateInBatches(values []*models.Announcement, 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 announcementDo) Save(values ...*models.Announcement) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a announcementDo) First() (*models.Announcement, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.Announcement), nil
}
}
func (a announcementDo) Take() (*models.Announcement, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.Announcement), nil
}
}
func (a announcementDo) Last() (*models.Announcement, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.Announcement), nil
}
}
func (a announcementDo) Find() ([]*models.Announcement, error) {
result, err := a.DO.Find()
return result.([]*models.Announcement), err
}
func (a announcementDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Announcement, err error) {
buf := make([]*models.Announcement, 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 announcementDo) FindInBatches(result *[]*models.Announcement, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a announcementDo) Attrs(attrs ...field.AssignExpr) *announcementDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a announcementDo) Assign(attrs ...field.AssignExpr) *announcementDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a announcementDo) Joins(fields ...field.RelationField) *announcementDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a announcementDo) Preload(fields ...field.RelationField) *announcementDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a announcementDo) FirstOrInit() (*models.Announcement, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.Announcement), nil
}
}
func (a announcementDo) FirstOrCreate() (*models.Announcement, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.Announcement), nil
}
}
func (a announcementDo) FindByPage(offset int, limit int) (result []*models.Announcement, 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 announcementDo) 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 announcementDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a announcementDo) Delete(models ...*models.Announcement) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *announcementDo) withDO(do gen.Dao) *announcementDo {
a.DO = *do.(*gen.DO)
return a
}