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.
366 lines
9.2 KiB
Go
366 lines
9.2 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 newPhoto(db *gorm.DB, opts ...gen.DOOption) photo {
|
|
_photo := photo{}
|
|
|
|
_photo.photoDo.UseDB(db, opts...)
|
|
_photo.photoDo.UseModel(&entity.Photo{})
|
|
|
|
tableName := _photo.photoDo.TableName()
|
|
_photo.ALL = field.NewAsterisk(tableName)
|
|
_photo.ID = field.NewInt32(tableName, "id")
|
|
_photo.CreateTime = field.NewTime(tableName, "create_time")
|
|
_photo.UpdateTime = field.NewTime(tableName, "update_time")
|
|
_photo.Description = field.NewString(tableName, "description")
|
|
_photo.Location = field.NewString(tableName, "location")
|
|
_photo.Name = field.NewString(tableName, "name")
|
|
_photo.TakeTime = field.NewTime(tableName, "take_time")
|
|
_photo.Team = field.NewString(tableName, "team")
|
|
_photo.Thumbnail = field.NewString(tableName, "thumbnail")
|
|
_photo.URL = field.NewString(tableName, "url")
|
|
_photo.Likes = field.NewInt64(tableName, "likes")
|
|
|
|
_photo.fillFieldMap()
|
|
|
|
return _photo
|
|
}
|
|
|
|
type photo struct {
|
|
photoDo photoDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
CreateTime field.Time
|
|
UpdateTime field.Time
|
|
Description field.String
|
|
Location field.String
|
|
Name field.String
|
|
TakeTime field.Time
|
|
Team field.String
|
|
Thumbnail field.String
|
|
URL field.String
|
|
Likes field.Int64
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (p photo) Table(newTableName string) *photo {
|
|
p.photoDo.UseTable(newTableName)
|
|
return p.updateTableName(newTableName)
|
|
}
|
|
|
|
func (p photo) As(alias string) *photo {
|
|
p.photoDo.DO = *(p.photoDo.As(alias).(*gen.DO))
|
|
return p.updateTableName(alias)
|
|
}
|
|
|
|
func (p *photo) updateTableName(table string) *photo {
|
|
p.ALL = field.NewAsterisk(table)
|
|
p.ID = field.NewInt32(table, "id")
|
|
p.CreateTime = field.NewTime(table, "create_time")
|
|
p.UpdateTime = field.NewTime(table, "update_time")
|
|
p.Description = field.NewString(table, "description")
|
|
p.Location = field.NewString(table, "location")
|
|
p.Name = field.NewString(table, "name")
|
|
p.TakeTime = field.NewTime(table, "take_time")
|
|
p.Team = field.NewString(table, "team")
|
|
p.Thumbnail = field.NewString(table, "thumbnail")
|
|
p.URL = field.NewString(table, "url")
|
|
p.Likes = field.NewInt64(table, "likes")
|
|
|
|
p.fillFieldMap()
|
|
|
|
return p
|
|
}
|
|
|
|
func (p *photo) WithContext(ctx context.Context) *photoDo { return p.photoDo.WithContext(ctx) }
|
|
|
|
func (p photo) TableName() string { return p.photoDo.TableName() }
|
|
|
|
func (p photo) Alias() string { return p.photoDo.Alias() }
|
|
|
|
func (p photo) Columns(cols ...field.Expr) gen.Columns { return p.photoDo.Columns(cols...) }
|
|
|
|
func (p *photo) 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 *photo) fillFieldMap() {
|
|
p.fieldMap = make(map[string]field.Expr, 11)
|
|
p.fieldMap["id"] = p.ID
|
|
p.fieldMap["create_time"] = p.CreateTime
|
|
p.fieldMap["update_time"] = p.UpdateTime
|
|
p.fieldMap["description"] = p.Description
|
|
p.fieldMap["location"] = p.Location
|
|
p.fieldMap["name"] = p.Name
|
|
p.fieldMap["take_time"] = p.TakeTime
|
|
p.fieldMap["team"] = p.Team
|
|
p.fieldMap["thumbnail"] = p.Thumbnail
|
|
p.fieldMap["url"] = p.URL
|
|
p.fieldMap["likes"] = p.Likes
|
|
}
|
|
|
|
func (p photo) clone(db *gorm.DB) photo {
|
|
p.photoDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return p
|
|
}
|
|
|
|
func (p photo) replaceDB(db *gorm.DB) photo {
|
|
p.photoDo.ReplaceDB(db)
|
|
return p
|
|
}
|
|
|
|
type photoDo struct{ gen.DO }
|
|
|
|
func (p photoDo) Debug() *photoDo {
|
|
return p.withDO(p.DO.Debug())
|
|
}
|
|
|
|
func (p photoDo) WithContext(ctx context.Context) *photoDo {
|
|
return p.withDO(p.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (p photoDo) ReadDB() *photoDo {
|
|
return p.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (p photoDo) WriteDB() *photoDo {
|
|
return p.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (p photoDo) Session(config *gorm.Session) *photoDo {
|
|
return p.withDO(p.DO.Session(config))
|
|
}
|
|
|
|
func (p photoDo) Clauses(conds ...clause.Expression) *photoDo {
|
|
return p.withDO(p.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (p photoDo) Returning(value interface{}, columns ...string) *photoDo {
|
|
return p.withDO(p.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (p photoDo) Not(conds ...gen.Condition) *photoDo {
|
|
return p.withDO(p.DO.Not(conds...))
|
|
}
|
|
|
|
func (p photoDo) Or(conds ...gen.Condition) *photoDo {
|
|
return p.withDO(p.DO.Or(conds...))
|
|
}
|
|
|
|
func (p photoDo) Select(conds ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.Select(conds...))
|
|
}
|
|
|
|
func (p photoDo) Where(conds ...gen.Condition) *photoDo {
|
|
return p.withDO(p.DO.Where(conds...))
|
|
}
|
|
|
|
func (p photoDo) Order(conds ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.Order(conds...))
|
|
}
|
|
|
|
func (p photoDo) Distinct(cols ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (p photoDo) Omit(cols ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.Omit(cols...))
|
|
}
|
|
|
|
func (p photoDo) Join(table schema.Tabler, on ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.Join(table, on...))
|
|
}
|
|
|
|
func (p photoDo) LeftJoin(table schema.Tabler, on ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (p photoDo) RightJoin(table schema.Tabler, on ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (p photoDo) Group(cols ...field.Expr) *photoDo {
|
|
return p.withDO(p.DO.Group(cols...))
|
|
}
|
|
|
|
func (p photoDo) Having(conds ...gen.Condition) *photoDo {
|
|
return p.withDO(p.DO.Having(conds...))
|
|
}
|
|
|
|
func (p photoDo) Limit(limit int) *photoDo {
|
|
return p.withDO(p.DO.Limit(limit))
|
|
}
|
|
|
|
func (p photoDo) Offset(offset int) *photoDo {
|
|
return p.withDO(p.DO.Offset(offset))
|
|
}
|
|
|
|
func (p photoDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *photoDo {
|
|
return p.withDO(p.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (p photoDo) Unscoped() *photoDo {
|
|
return p.withDO(p.DO.Unscoped())
|
|
}
|
|
|
|
func (p photoDo) Create(values ...*entity.Photo) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Create(values)
|
|
}
|
|
|
|
func (p photoDo) CreateInBatches(values []*entity.Photo, 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 photoDo) Save(values ...*entity.Photo) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return p.DO.Save(values)
|
|
}
|
|
|
|
func (p photoDo) First() (*entity.Photo, error) {
|
|
if result, err := p.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Photo), nil
|
|
}
|
|
}
|
|
|
|
func (p photoDo) Take() (*entity.Photo, error) {
|
|
if result, err := p.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Photo), nil
|
|
}
|
|
}
|
|
|
|
func (p photoDo) Last() (*entity.Photo, error) {
|
|
if result, err := p.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Photo), nil
|
|
}
|
|
}
|
|
|
|
func (p photoDo) Find() ([]*entity.Photo, error) {
|
|
result, err := p.DO.Find()
|
|
return result.([]*entity.Photo), err
|
|
}
|
|
|
|
func (p photoDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Photo, err error) {
|
|
buf := make([]*entity.Photo, 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 photoDo) FindInBatches(result *[]*entity.Photo, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return p.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (p photoDo) Attrs(attrs ...field.AssignExpr) *photoDo {
|
|
return p.withDO(p.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (p photoDo) Assign(attrs ...field.AssignExpr) *photoDo {
|
|
return p.withDO(p.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (p photoDo) Joins(fields ...field.RelationField) *photoDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Joins(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p photoDo) Preload(fields ...field.RelationField) *photoDo {
|
|
for _, _f := range fields {
|
|
p = *p.withDO(p.DO.Preload(_f))
|
|
}
|
|
return &p
|
|
}
|
|
|
|
func (p photoDo) FirstOrInit() (*entity.Photo, error) {
|
|
if result, err := p.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Photo), nil
|
|
}
|
|
}
|
|
|
|
func (p photoDo) FirstOrCreate() (*entity.Photo, error) {
|
|
if result, err := p.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*entity.Photo), nil
|
|
}
|
|
}
|
|
|
|
func (p photoDo) FindByPage(offset int, limit int) (result []*entity.Photo, 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 photoDo) 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 photoDo) Scan(result interface{}) (err error) {
|
|
return p.DO.Scan(result)
|
|
}
|
|
|
|
func (p photoDo) Delete(models ...*entity.Photo) (result gen.ResultInfo, err error) {
|
|
return p.DO.Delete(models)
|
|
}
|
|
|
|
func (p *photoDo) withDO(do gen.Dao) *photoDo {
|
|
p.DO = *do.(*gen.DO)
|
|
return p
|
|
}
|