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.
sonic/dal/attachment.gen.go

376 lines
10 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 newAttachment(db *gorm.DB, opts ...gen.DOOption) attachment {
_attachment := attachment{}
_attachment.attachmentDo.UseDB(db, opts...)
_attachment.attachmentDo.UseModel(&entity.Attachment{})
tableName := _attachment.attachmentDo.TableName()
_attachment.ALL = field.NewAsterisk(tableName)
_attachment.ID = field.NewInt32(tableName, "id")
_attachment.CreateTime = field.NewTime(tableName, "create_time")
_attachment.UpdateTime = field.NewTime(tableName, "update_time")
_attachment.FileKey = field.NewString(tableName, "file_key")
_attachment.Height = field.NewInt32(tableName, "height")
_attachment.MediaType = field.NewString(tableName, "media_type")
_attachment.Name = field.NewString(tableName, "name")
_attachment.Path = field.NewString(tableName, "path")
_attachment.Size = field.NewInt64(tableName, "size")
_attachment.Suffix = field.NewString(tableName, "suffix")
_attachment.ThumbPath = field.NewString(tableName, "thumb_path")
_attachment.Type = field.NewField(tableName, "type")
_attachment.Width = field.NewInt32(tableName, "width")
_attachment.fillFieldMap()
return _attachment
}
type attachment struct {
attachmentDo attachmentDo
ALL field.Asterisk
ID field.Int32
CreateTime field.Time
UpdateTime field.Time
FileKey field.String
Height field.Int32
MediaType field.String
Name field.String
Path field.String
Size field.Int64
Suffix field.String
ThumbPath field.String
Type field.Field
Width field.Int32
fieldMap map[string]field.Expr
}
func (a attachment) Table(newTableName string) *attachment {
a.attachmentDo.UseTable(newTableName)
return a.updateTableName(newTableName)
}
func (a attachment) As(alias string) *attachment {
a.attachmentDo.DO = *(a.attachmentDo.As(alias).(*gen.DO))
return a.updateTableName(alias)
}
func (a *attachment) updateTableName(table string) *attachment {
a.ALL = field.NewAsterisk(table)
a.ID = field.NewInt32(table, "id")
a.CreateTime = field.NewTime(table, "create_time")
a.UpdateTime = field.NewTime(table, "update_time")
a.FileKey = field.NewString(table, "file_key")
a.Height = field.NewInt32(table, "height")
a.MediaType = field.NewString(table, "media_type")
a.Name = field.NewString(table, "name")
a.Path = field.NewString(table, "path")
a.Size = field.NewInt64(table, "size")
a.Suffix = field.NewString(table, "suffix")
a.ThumbPath = field.NewString(table, "thumb_path")
a.Type = field.NewField(table, "type")
a.Width = field.NewInt32(table, "width")
a.fillFieldMap()
return a
}
func (a *attachment) WithContext(ctx context.Context) *attachmentDo {
return a.attachmentDo.WithContext(ctx)
}
func (a attachment) TableName() string { return a.attachmentDo.TableName() }
func (a attachment) Alias() string { return a.attachmentDo.Alias() }
func (a attachment) Columns(cols ...field.Expr) gen.Columns { return a.attachmentDo.Columns(cols...) }
func (a *attachment) 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 *attachment) fillFieldMap() {
a.fieldMap = make(map[string]field.Expr, 13)
a.fieldMap["id"] = a.ID
a.fieldMap["create_time"] = a.CreateTime
a.fieldMap["update_time"] = a.UpdateTime
a.fieldMap["file_key"] = a.FileKey
a.fieldMap["height"] = a.Height
a.fieldMap["media_type"] = a.MediaType
a.fieldMap["name"] = a.Name
a.fieldMap["path"] = a.Path
a.fieldMap["size"] = a.Size
a.fieldMap["suffix"] = a.Suffix
a.fieldMap["thumb_path"] = a.ThumbPath
a.fieldMap["type"] = a.Type
a.fieldMap["width"] = a.Width
}
func (a attachment) clone(db *gorm.DB) attachment {
a.attachmentDo.ReplaceConnPool(db.Statement.ConnPool)
return a
}
func (a attachment) replaceDB(db *gorm.DB) attachment {
a.attachmentDo.ReplaceDB(db)
return a
}
type attachmentDo struct{ gen.DO }
func (a attachmentDo) Debug() *attachmentDo {
return a.withDO(a.DO.Debug())
}
func (a attachmentDo) WithContext(ctx context.Context) *attachmentDo {
return a.withDO(a.DO.WithContext(ctx))
}
func (a attachmentDo) ReadDB() *attachmentDo {
return a.Clauses(dbresolver.Read)
}
func (a attachmentDo) WriteDB() *attachmentDo {
return a.Clauses(dbresolver.Write)
}
func (a attachmentDo) Session(config *gorm.Session) *attachmentDo {
return a.withDO(a.DO.Session(config))
}
func (a attachmentDo) Clauses(conds ...clause.Expression) *attachmentDo {
return a.withDO(a.DO.Clauses(conds...))
}
func (a attachmentDo) Returning(value interface{}, columns ...string) *attachmentDo {
return a.withDO(a.DO.Returning(value, columns...))
}
func (a attachmentDo) Not(conds ...gen.Condition) *attachmentDo {
return a.withDO(a.DO.Not(conds...))
}
func (a attachmentDo) Or(conds ...gen.Condition) *attachmentDo {
return a.withDO(a.DO.Or(conds...))
}
func (a attachmentDo) Select(conds ...field.Expr) *attachmentDo {
return a.withDO(a.DO.Select(conds...))
}
func (a attachmentDo) Where(conds ...gen.Condition) *attachmentDo {
return a.withDO(a.DO.Where(conds...))
}
func (a attachmentDo) Order(conds ...field.Expr) *attachmentDo {
return a.withDO(a.DO.Order(conds...))
}
func (a attachmentDo) Distinct(cols ...field.Expr) *attachmentDo {
return a.withDO(a.DO.Distinct(cols...))
}
func (a attachmentDo) Omit(cols ...field.Expr) *attachmentDo {
return a.withDO(a.DO.Omit(cols...))
}
func (a attachmentDo) Join(table schema.Tabler, on ...field.Expr) *attachmentDo {
return a.withDO(a.DO.Join(table, on...))
}
func (a attachmentDo) LeftJoin(table schema.Tabler, on ...field.Expr) *attachmentDo {
return a.withDO(a.DO.LeftJoin(table, on...))
}
func (a attachmentDo) RightJoin(table schema.Tabler, on ...field.Expr) *attachmentDo {
return a.withDO(a.DO.RightJoin(table, on...))
}
func (a attachmentDo) Group(cols ...field.Expr) *attachmentDo {
return a.withDO(a.DO.Group(cols...))
}
func (a attachmentDo) Having(conds ...gen.Condition) *attachmentDo {
return a.withDO(a.DO.Having(conds...))
}
func (a attachmentDo) Limit(limit int) *attachmentDo {
return a.withDO(a.DO.Limit(limit))
}
func (a attachmentDo) Offset(offset int) *attachmentDo {
return a.withDO(a.DO.Offset(offset))
}
func (a attachmentDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *attachmentDo {
return a.withDO(a.DO.Scopes(funcs...))
}
func (a attachmentDo) Unscoped() *attachmentDo {
return a.withDO(a.DO.Unscoped())
}
func (a attachmentDo) Create(values ...*entity.Attachment) error {
if len(values) == 0 {
return nil
}
return a.DO.Create(values)
}
func (a attachmentDo) CreateInBatches(values []*entity.Attachment, 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 attachmentDo) Save(values ...*entity.Attachment) error {
if len(values) == 0 {
return nil
}
return a.DO.Save(values)
}
func (a attachmentDo) First() (*entity.Attachment, error) {
if result, err := a.DO.First(); err != nil {
return nil, err
} else {
return result.(*entity.Attachment), nil
}
}
func (a attachmentDo) Take() (*entity.Attachment, error) {
if result, err := a.DO.Take(); err != nil {
return nil, err
} else {
return result.(*entity.Attachment), nil
}
}
func (a attachmentDo) Last() (*entity.Attachment, error) {
if result, err := a.DO.Last(); err != nil {
return nil, err
} else {
return result.(*entity.Attachment), nil
}
}
func (a attachmentDo) Find() ([]*entity.Attachment, error) {
result, err := a.DO.Find()
return result.([]*entity.Attachment), err
}
func (a attachmentDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Attachment, err error) {
buf := make([]*entity.Attachment, 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 attachmentDo) FindInBatches(result *[]*entity.Attachment, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return a.DO.FindInBatches(result, batchSize, fc)
}
func (a attachmentDo) Attrs(attrs ...field.AssignExpr) *attachmentDo {
return a.withDO(a.DO.Attrs(attrs...))
}
func (a attachmentDo) Assign(attrs ...field.AssignExpr) *attachmentDo {
return a.withDO(a.DO.Assign(attrs...))
}
func (a attachmentDo) Joins(fields ...field.RelationField) *attachmentDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Joins(_f))
}
return &a
}
func (a attachmentDo) Preload(fields ...field.RelationField) *attachmentDo {
for _, _f := range fields {
a = *a.withDO(a.DO.Preload(_f))
}
return &a
}
func (a attachmentDo) FirstOrInit() (*entity.Attachment, error) {
if result, err := a.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*entity.Attachment), nil
}
}
func (a attachmentDo) FirstOrCreate() (*entity.Attachment, error) {
if result, err := a.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*entity.Attachment), nil
}
}
func (a attachmentDo) FindByPage(offset int, limit int) (result []*entity.Attachment, 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 attachmentDo) 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 attachmentDo) Scan(result interface{}) (err error) {
return a.DO.Scan(result)
}
func (a attachmentDo) Delete(models ...*entity.Attachment) (result gen.ResultInfo, err error) {
return a.DO.Delete(models)
}
func (a *attachmentDo) withDO(do gen.Dao) *attachmentDo {
a.DO = *do.(*gen.DO)
return a
}