// 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 query

import (
	"context"

	"gorm.io/gorm"
	"gorm.io/gorm/clause"
	"gorm.io/gorm/schema"

	"gorm.io/gen"
	"gorm.io/gen/field"

	"gorm.io/plugin/dbresolver"

	"gadmin/internal/gorm/model"
)

func newLady38rank2(db *gorm.DB, opts ...gen.DOOption) lady38rank2 {
	_lady38rank2 := lady38rank2{}

	_lady38rank2.lady38rank2Do.UseDB(db, opts...)
	_lady38rank2.lady38rank2Do.UseModel(&model.Lady38rank2{})

	tableName := _lady38rank2.lady38rank2Do.TableName()
	_lady38rank2.ALL = field.NewAsterisk(tableName)
	_lady38rank2.Mingci = field.NewInt64(tableName, "mingci")
	_lady38rank2.Score = field.NewInt64(tableName, "score")
	_lady38rank2.ID = field.NewInt32(tableName, "id")

	_lady38rank2.fillFieldMap()

	return _lady38rank2
}

type lady38rank2 struct {
	lady38rank2Do

	ALL    field.Asterisk
	Mingci field.Int64
	Score  field.Int64
	ID     field.Int32

	fieldMap map[string]field.Expr
}

func (l lady38rank2) Table(newTableName string) *lady38rank2 {
	l.lady38rank2Do.UseTable(newTableName)
	return l.updateTableName(newTableName)
}

func (l lady38rank2) As(alias string) *lady38rank2 {
	l.lady38rank2Do.DO = *(l.lady38rank2Do.As(alias).(*gen.DO))
	return l.updateTableName(alias)
}

func (l *lady38rank2) updateTableName(table string) *lady38rank2 {
	l.ALL = field.NewAsterisk(table)
	l.Mingci = field.NewInt64(table, "mingci")
	l.Score = field.NewInt64(table, "score")
	l.ID = field.NewInt32(table, "id")

	l.fillFieldMap()

	return l
}

func (l *lady38rank2) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
	_f, ok := l.fieldMap[fieldName]
	if !ok || _f == nil {
		return nil, false
	}
	_oe, ok := _f.(field.OrderExpr)
	return _oe, ok
}

func (l *lady38rank2) fillFieldMap() {
	l.fieldMap = make(map[string]field.Expr, 3)
	l.fieldMap["mingci"] = l.Mingci
	l.fieldMap["score"] = l.Score
	l.fieldMap["id"] = l.ID
}

func (l lady38rank2) clone(db *gorm.DB) lady38rank2 {
	l.lady38rank2Do.ReplaceConnPool(db.Statement.ConnPool)
	return l
}

func (l lady38rank2) replaceDB(db *gorm.DB) lady38rank2 {
	l.lady38rank2Do.ReplaceDB(db)
	return l
}

type lady38rank2Do struct{ gen.DO }

func (l lady38rank2Do) Debug() *lady38rank2Do {
	return l.withDO(l.DO.Debug())
}

func (l lady38rank2Do) WithContext(ctx context.Context) *lady38rank2Do {
	return l.withDO(l.DO.WithContext(ctx))
}

func (l lady38rank2Do) ReadDB() *lady38rank2Do {
	return l.Clauses(dbresolver.Read)
}

func (l lady38rank2Do) WriteDB() *lady38rank2Do {
	return l.Clauses(dbresolver.Write)
}

func (l lady38rank2Do) Session(config *gorm.Session) *lady38rank2Do {
	return l.withDO(l.DO.Session(config))
}

func (l lady38rank2Do) Clauses(conds ...clause.Expression) *lady38rank2Do {
	return l.withDO(l.DO.Clauses(conds...))
}

func (l lady38rank2Do) Returning(value interface{}, columns ...string) *lady38rank2Do {
	return l.withDO(l.DO.Returning(value, columns...))
}

func (l lady38rank2Do) Not(conds ...gen.Condition) *lady38rank2Do {
	return l.withDO(l.DO.Not(conds...))
}

func (l lady38rank2Do) Or(conds ...gen.Condition) *lady38rank2Do {
	return l.withDO(l.DO.Or(conds...))
}

func (l lady38rank2Do) Select(conds ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.Select(conds...))
}

func (l lady38rank2Do) Where(conds ...gen.Condition) *lady38rank2Do {
	return l.withDO(l.DO.Where(conds...))
}

func (l lady38rank2Do) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) *lady38rank2Do {
	return l.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
}

func (l lady38rank2Do) Order(conds ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.Order(conds...))
}

func (l lady38rank2Do) Distinct(cols ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.Distinct(cols...))
}

func (l lady38rank2Do) Omit(cols ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.Omit(cols...))
}

func (l lady38rank2Do) Join(table schema.Tabler, on ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.Join(table, on...))
}

func (l lady38rank2Do) LeftJoin(table schema.Tabler, on ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.LeftJoin(table, on...))
}

func (l lady38rank2Do) RightJoin(table schema.Tabler, on ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.RightJoin(table, on...))
}

func (l lady38rank2Do) Group(cols ...field.Expr) *lady38rank2Do {
	return l.withDO(l.DO.Group(cols...))
}

func (l lady38rank2Do) Having(conds ...gen.Condition) *lady38rank2Do {
	return l.withDO(l.DO.Having(conds...))
}

func (l lady38rank2Do) Limit(limit int) *lady38rank2Do {
	return l.withDO(l.DO.Limit(limit))
}

func (l lady38rank2Do) Offset(offset int) *lady38rank2Do {
	return l.withDO(l.DO.Offset(offset))
}

func (l lady38rank2Do) Scopes(funcs ...func(gen.Dao) gen.Dao) *lady38rank2Do {
	return l.withDO(l.DO.Scopes(funcs...))
}

func (l lady38rank2Do) Unscoped() *lady38rank2Do {
	return l.withDO(l.DO.Unscoped())
}

func (l lady38rank2Do) Create(values ...*model.Lady38rank2) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Create(values)
}

func (l lady38rank2Do) CreateInBatches(values []*model.Lady38rank2, batchSize int) error {
	return l.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 (l lady38rank2Do) Save(values ...*model.Lady38rank2) error {
	if len(values) == 0 {
		return nil
	}
	return l.DO.Save(values)
}

func (l lady38rank2Do) First() (*model.Lady38rank2, error) {
	if result, err := l.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.Lady38rank2), nil
	}
}

func (l lady38rank2Do) Take() (*model.Lady38rank2, error) {
	if result, err := l.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.Lady38rank2), nil
	}
}

func (l lady38rank2Do) Last() (*model.Lady38rank2, error) {
	if result, err := l.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.Lady38rank2), nil
	}
}

func (l lady38rank2Do) Find() ([]*model.Lady38rank2, error) {
	result, err := l.DO.Find()
	return result.([]*model.Lady38rank2), err
}

func (l lady38rank2Do) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*model.Lady38rank2, err error) {
	buf := make([]*model.Lady38rank2, 0, batchSize)
	err = l.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 (l lady38rank2Do) FindInBatches(result *[]*model.Lady38rank2, batchSize int, fc func(tx gen.Dao, batch int) error) error {
	return l.DO.FindInBatches(result, batchSize, fc)
}

func (l lady38rank2Do) Attrs(attrs ...field.AssignExpr) *lady38rank2Do {
	return l.withDO(l.DO.Attrs(attrs...))
}

func (l lady38rank2Do) Assign(attrs ...field.AssignExpr) *lady38rank2Do {
	return l.withDO(l.DO.Assign(attrs...))
}

func (l lady38rank2Do) Joins(fields ...field.RelationField) *lady38rank2Do {
	for _, _f := range fields {
		l = *l.withDO(l.DO.Joins(_f))
	}
	return &l
}

func (l lady38rank2Do) Preload(fields ...field.RelationField) *lady38rank2Do {
	for _, _f := range fields {
		l = *l.withDO(l.DO.Preload(_f))
	}
	return &l
}

func (l lady38rank2Do) FirstOrInit() (*model.Lady38rank2, error) {
	if result, err := l.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.Lady38rank2), nil
	}
}

func (l lady38rank2Do) FirstOrCreate() (*model.Lady38rank2, error) {
	if result, err := l.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.Lady38rank2), nil
	}
}

func (l lady38rank2Do) FindByPage(offset int, limit int) (result []*model.Lady38rank2, count int64, err error) {
	result, err = l.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 = l.Offset(-1).Limit(-1).Count()
	return
}

func (l lady38rank2Do) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
	count, err = l.Count()
	if err != nil {
		return
	}

	err = l.Offset(offset).Limit(limit).Scan(result)
	return
}

func (l lady38rank2Do) Scan(result interface{}) (err error) {
	return l.DO.Scan(result)
}

func (l lady38rank2Do) Delete(models ...*model.Lady38rank2) (result gen.ResultInfo, err error) {
	return l.DO.Delete(models)
}

func (l *lady38rank2Do) withDO(do gen.Dao) *lady38rank2Do {
	l.DO = *do.(*gen.DO)
	return l
}
