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

	_onlineNumsLog.onlineNumsLogDo.UseDB(db, opts...)
	_onlineNumsLog.onlineNumsLogDo.UseModel(&model.OnlineNumsLog{})

	tableName := _onlineNumsLog.onlineNumsLogDo.TableName()
	_onlineNumsLog.ALL = field.NewAsterisk(tableName)
	_onlineNumsLog.ID = field.NewInt64(tableName, "id")
	_onlineNumsLog.Stamp = field.NewInt32(tableName, "stamp")
	_onlineNumsLog.Nums = field.NewInt32(tableName, "nums")
	_onlineNumsLog.ServerID = field.NewInt32(tableName, "server_id")

	_onlineNumsLog.fillFieldMap()

	return _onlineNumsLog
}

type onlineNumsLog struct {
	onlineNumsLogDo

	ALL      field.Asterisk
	ID       field.Int64
	Stamp    field.Int32
	Nums     field.Int32 // 在线人数
	ServerID field.Int32 // 服务器id

	fieldMap map[string]field.Expr
}

func (o onlineNumsLog) Table(newTableName string) *onlineNumsLog {
	o.onlineNumsLogDo.UseTable(newTableName)
	return o.updateTableName(newTableName)
}

func (o onlineNumsLog) As(alias string) *onlineNumsLog {
	o.onlineNumsLogDo.DO = *(o.onlineNumsLogDo.As(alias).(*gen.DO))
	return o.updateTableName(alias)
}

func (o *onlineNumsLog) updateTableName(table string) *onlineNumsLog {
	o.ALL = field.NewAsterisk(table)
	o.ID = field.NewInt64(table, "id")
	o.Stamp = field.NewInt32(table, "stamp")
	o.Nums = field.NewInt32(table, "nums")
	o.ServerID = field.NewInt32(table, "server_id")

	o.fillFieldMap()

	return o
}

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

func (o *onlineNumsLog) fillFieldMap() {
	o.fieldMap = make(map[string]field.Expr, 4)
	o.fieldMap["id"] = o.ID
	o.fieldMap["stamp"] = o.Stamp
	o.fieldMap["nums"] = o.Nums
	o.fieldMap["server_id"] = o.ServerID
}

func (o onlineNumsLog) clone(db *gorm.DB) onlineNumsLog {
	o.onlineNumsLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return o
}

func (o onlineNumsLog) replaceDB(db *gorm.DB) onlineNumsLog {
	o.onlineNumsLogDo.ReplaceDB(db)
	return o
}

type onlineNumsLogDo struct{ gen.DO }

func (o onlineNumsLogDo) Debug() *onlineNumsLogDo {
	return o.withDO(o.DO.Debug())
}

func (o onlineNumsLogDo) WithContext(ctx context.Context) *onlineNumsLogDo {
	return o.withDO(o.DO.WithContext(ctx))
}

func (o onlineNumsLogDo) ReadDB() *onlineNumsLogDo {
	return o.Clauses(dbresolver.Read)
}

func (o onlineNumsLogDo) WriteDB() *onlineNumsLogDo {
	return o.Clauses(dbresolver.Write)
}

func (o onlineNumsLogDo) Session(config *gorm.Session) *onlineNumsLogDo {
	return o.withDO(o.DO.Session(config))
}

func (o onlineNumsLogDo) Clauses(conds ...clause.Expression) *onlineNumsLogDo {
	return o.withDO(o.DO.Clauses(conds...))
}

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

func (o onlineNumsLogDo) Not(conds ...gen.Condition) *onlineNumsLogDo {
	return o.withDO(o.DO.Not(conds...))
}

func (o onlineNumsLogDo) Or(conds ...gen.Condition) *onlineNumsLogDo {
	return o.withDO(o.DO.Or(conds...))
}

func (o onlineNumsLogDo) Select(conds ...field.Expr) *onlineNumsLogDo {
	return o.withDO(o.DO.Select(conds...))
}

func (o onlineNumsLogDo) Where(conds ...gen.Condition) *onlineNumsLogDo {
	return o.withDO(o.DO.Where(conds...))
}

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

func (o onlineNumsLogDo) Order(conds ...field.Expr) *onlineNumsLogDo {
	return o.withDO(o.DO.Order(conds...))
}

func (o onlineNumsLogDo) Distinct(cols ...field.Expr) *onlineNumsLogDo {
	return o.withDO(o.DO.Distinct(cols...))
}

func (o onlineNumsLogDo) Omit(cols ...field.Expr) *onlineNumsLogDo {
	return o.withDO(o.DO.Omit(cols...))
}

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

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

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

func (o onlineNumsLogDo) Group(cols ...field.Expr) *onlineNumsLogDo {
	return o.withDO(o.DO.Group(cols...))
}

func (o onlineNumsLogDo) Having(conds ...gen.Condition) *onlineNumsLogDo {
	return o.withDO(o.DO.Having(conds...))
}

func (o onlineNumsLogDo) Limit(limit int) *onlineNumsLogDo {
	return o.withDO(o.DO.Limit(limit))
}

func (o onlineNumsLogDo) Offset(offset int) *onlineNumsLogDo {
	return o.withDO(o.DO.Offset(offset))
}

func (o onlineNumsLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *onlineNumsLogDo {
	return o.withDO(o.DO.Scopes(funcs...))
}

func (o onlineNumsLogDo) Unscoped() *onlineNumsLogDo {
	return o.withDO(o.DO.Unscoped())
}

func (o onlineNumsLogDo) Create(values ...*model.OnlineNumsLog) error {
	if len(values) == 0 {
		return nil
	}
	return o.DO.Create(values)
}

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

func (o onlineNumsLogDo) First() (*model.OnlineNumsLog, error) {
	if result, err := o.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.OnlineNumsLog), nil
	}
}

func (o onlineNumsLogDo) Take() (*model.OnlineNumsLog, error) {
	if result, err := o.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.OnlineNumsLog), nil
	}
}

func (o onlineNumsLogDo) Last() (*model.OnlineNumsLog, error) {
	if result, err := o.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.OnlineNumsLog), nil
	}
}

func (o onlineNumsLogDo) Find() ([]*model.OnlineNumsLog, error) {
	result, err := o.DO.Find()
	return result.([]*model.OnlineNumsLog), err
}

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

func (o onlineNumsLogDo) Attrs(attrs ...field.AssignExpr) *onlineNumsLogDo {
	return o.withDO(o.DO.Attrs(attrs...))
}

func (o onlineNumsLogDo) Assign(attrs ...field.AssignExpr) *onlineNumsLogDo {
	return o.withDO(o.DO.Assign(attrs...))
}

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

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

func (o onlineNumsLogDo) FirstOrInit() (*model.OnlineNumsLog, error) {
	if result, err := o.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.OnlineNumsLog), nil
	}
}

func (o onlineNumsLogDo) FirstOrCreate() (*model.OnlineNumsLog, error) {
	if result, err := o.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.OnlineNumsLog), nil
	}
}

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

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

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

func (o onlineNumsLogDo) Scan(result interface{}) (err error) {
	return o.DO.Scan(result)
}

func (o onlineNumsLogDo) Delete(models ...*model.OnlineNumsLog) (result gen.ResultInfo, err error) {
	return o.DO.Delete(models)
}

func (o *onlineNumsLogDo) withDO(do gen.Dao) *onlineNumsLogDo {
	o.DO = *do.(*gen.DO)
	return o
}
