// 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 newPlayerLogin(db *gorm.DB, opts ...gen.DOOption) playerLogin {
	_playerLogin := playerLogin{}

	_playerLogin.playerLoginDo.UseDB(db, opts...)
	_playerLogin.playerLoginDo.UseModel(&model.PlayerLogin{})

	tableName := _playerLogin.playerLoginDo.TableName()
	_playerLogin.ALL = field.NewAsterisk(tableName)
	_playerLogin.ID = field.NewInt64(tableName, "id")
	_playerLogin.Playerid = field.NewInt64(tableName, "playerid")
	_playerLogin.Times = field.NewInt32(tableName, "times")

	_playerLogin.fillFieldMap()

	return _playerLogin
}

type playerLogin struct {
	playerLoginDo

	ALL      field.Asterisk
	ID       field.Int64
	Playerid field.Int64 // 用户ID
	Times    field.Int32 // 登录次数

	fieldMap map[string]field.Expr
}

func (p playerLogin) Table(newTableName string) *playerLogin {
	p.playerLoginDo.UseTable(newTableName)
	return p.updateTableName(newTableName)
}

func (p playerLogin) As(alias string) *playerLogin {
	p.playerLoginDo.DO = *(p.playerLoginDo.As(alias).(*gen.DO))
	return p.updateTableName(alias)
}

func (p *playerLogin) updateTableName(table string) *playerLogin {
	p.ALL = field.NewAsterisk(table)
	p.ID = field.NewInt64(table, "id")
	p.Playerid = field.NewInt64(table, "playerid")
	p.Times = field.NewInt32(table, "times")

	p.fillFieldMap()

	return p
}

func (p *playerLogin) 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 *playerLogin) fillFieldMap() {
	p.fieldMap = make(map[string]field.Expr, 3)
	p.fieldMap["id"] = p.ID
	p.fieldMap["playerid"] = p.Playerid
	p.fieldMap["times"] = p.Times
}

func (p playerLogin) clone(db *gorm.DB) playerLogin {
	p.playerLoginDo.ReplaceConnPool(db.Statement.ConnPool)
	return p
}

func (p playerLogin) replaceDB(db *gorm.DB) playerLogin {
	p.playerLoginDo.ReplaceDB(db)
	return p
}

type playerLoginDo struct{ gen.DO }

func (p playerLoginDo) Debug() *playerLoginDo {
	return p.withDO(p.DO.Debug())
}

func (p playerLoginDo) WithContext(ctx context.Context) *playerLoginDo {
	return p.withDO(p.DO.WithContext(ctx))
}

func (p playerLoginDo) ReadDB() *playerLoginDo {
	return p.Clauses(dbresolver.Read)
}

func (p playerLoginDo) WriteDB() *playerLoginDo {
	return p.Clauses(dbresolver.Write)
}

func (p playerLoginDo) Session(config *gorm.Session) *playerLoginDo {
	return p.withDO(p.DO.Session(config))
}

func (p playerLoginDo) Clauses(conds ...clause.Expression) *playerLoginDo {
	return p.withDO(p.DO.Clauses(conds...))
}

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

func (p playerLoginDo) Not(conds ...gen.Condition) *playerLoginDo {
	return p.withDO(p.DO.Not(conds...))
}

func (p playerLoginDo) Or(conds ...gen.Condition) *playerLoginDo {
	return p.withDO(p.DO.Or(conds...))
}

func (p playerLoginDo) Select(conds ...field.Expr) *playerLoginDo {
	return p.withDO(p.DO.Select(conds...))
}

func (p playerLoginDo) Where(conds ...gen.Condition) *playerLoginDo {
	return p.withDO(p.DO.Where(conds...))
}

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

func (p playerLoginDo) Order(conds ...field.Expr) *playerLoginDo {
	return p.withDO(p.DO.Order(conds...))
}

func (p playerLoginDo) Distinct(cols ...field.Expr) *playerLoginDo {
	return p.withDO(p.DO.Distinct(cols...))
}

func (p playerLoginDo) Omit(cols ...field.Expr) *playerLoginDo {
	return p.withDO(p.DO.Omit(cols...))
}

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

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

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

func (p playerLoginDo) Group(cols ...field.Expr) *playerLoginDo {
	return p.withDO(p.DO.Group(cols...))
}

func (p playerLoginDo) Having(conds ...gen.Condition) *playerLoginDo {
	return p.withDO(p.DO.Having(conds...))
}

func (p playerLoginDo) Limit(limit int) *playerLoginDo {
	return p.withDO(p.DO.Limit(limit))
}

func (p playerLoginDo) Offset(offset int) *playerLoginDo {
	return p.withDO(p.DO.Offset(offset))
}

func (p playerLoginDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *playerLoginDo {
	return p.withDO(p.DO.Scopes(funcs...))
}

func (p playerLoginDo) Unscoped() *playerLoginDo {
	return p.withDO(p.DO.Unscoped())
}

func (p playerLoginDo) Create(values ...*model.PlayerLogin) error {
	if len(values) == 0 {
		return nil
	}
	return p.DO.Create(values)
}

func (p playerLoginDo) CreateInBatches(values []*model.PlayerLogin, 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 playerLoginDo) Save(values ...*model.PlayerLogin) error {
	if len(values) == 0 {
		return nil
	}
	return p.DO.Save(values)
}

func (p playerLoginDo) First() (*model.PlayerLogin, error) {
	if result, err := p.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerLogin), nil
	}
}

func (p playerLoginDo) Take() (*model.PlayerLogin, error) {
	if result, err := p.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerLogin), nil
	}
}

func (p playerLoginDo) Last() (*model.PlayerLogin, error) {
	if result, err := p.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerLogin), nil
	}
}

func (p playerLoginDo) Find() ([]*model.PlayerLogin, error) {
	result, err := p.DO.Find()
	return result.([]*model.PlayerLogin), err
}

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

func (p playerLoginDo) Attrs(attrs ...field.AssignExpr) *playerLoginDo {
	return p.withDO(p.DO.Attrs(attrs...))
}

func (p playerLoginDo) Assign(attrs ...field.AssignExpr) *playerLoginDo {
	return p.withDO(p.DO.Assign(attrs...))
}

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

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

func (p playerLoginDo) FirstOrInit() (*model.PlayerLogin, error) {
	if result, err := p.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerLogin), nil
	}
}

func (p playerLoginDo) FirstOrCreate() (*model.PlayerLogin, error) {
	if result, err := p.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.PlayerLogin), nil
	}
}

func (p playerLoginDo) FindByPage(offset int, limit int) (result []*model.PlayerLogin, 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 playerLoginDo) 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 playerLoginDo) Scan(result interface{}) (err error) {
	return p.DO.Scan(result)
}

func (p playerLoginDo) Delete(models ...*model.PlayerLogin) (result gen.ResultInfo, err error) {
	return p.DO.Delete(models)
}

func (p *playerLoginDo) withDO(do gen.Dao) *playerLoginDo {
	p.DO = *do.(*gen.DO)
	return p
}
