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

	_toolsRestartLog.toolsRestartLogDo.UseDB(db, opts...)
	_toolsRestartLog.toolsRestartLogDo.UseModel(&model.ToolsRestartLog{})

	tableName := _toolsRestartLog.toolsRestartLogDo.TableName()
	_toolsRestartLog.ALL = field.NewAsterisk(tableName)
	_toolsRestartLog.ID = field.NewInt64(tableName, "id")
	_toolsRestartLog.Version = field.NewString(tableName, "version")
	_toolsRestartLog.AdminID = field.NewInt64(tableName, "admin_id")
	_toolsRestartLog.Username = field.NewString(tableName, "username")
	_toolsRestartLog.IP = field.NewString(tableName, "ip")
	_toolsRestartLog.UserAgent = field.NewString(tableName, "user_agent")
	_toolsRestartLog.Command = field.NewString(tableName, "command")
	_toolsRestartLog.Stdout = field.NewString(tableName, "stdout")
	_toolsRestartLog.Latency = field.NewInt64(tableName, "latency")
	_toolsRestartLog.CreatedAt = field.NewTime(tableName, "created_at")
	_toolsRestartLog.UpdatedAt = field.NewTime(tableName, "updated_at")

	_toolsRestartLog.fillFieldMap()

	return _toolsRestartLog
}

type toolsRestartLog struct {
	toolsRestartLogDo

	ALL       field.Asterisk
	ID        field.Int64  // ID
	Version   field.String // 版本号
	AdminID   field.Int64  // 管理员ID
	Username  field.String // 操作用户
	IP        field.String // 操作IP
	UserAgent field.String // 访问代理
	Command   field.String // 重启命令
	Stdout    field.String // 执行日志
	Latency   field.Int64  // 耗时
	CreatedAt field.Time   // 创建时间
	UpdatedAt field.Time

	fieldMap map[string]field.Expr
}

func (t toolsRestartLog) Table(newTableName string) *toolsRestartLog {
	t.toolsRestartLogDo.UseTable(newTableName)
	return t.updateTableName(newTableName)
}

func (t toolsRestartLog) As(alias string) *toolsRestartLog {
	t.toolsRestartLogDo.DO = *(t.toolsRestartLogDo.As(alias).(*gen.DO))
	return t.updateTableName(alias)
}

func (t *toolsRestartLog) updateTableName(table string) *toolsRestartLog {
	t.ALL = field.NewAsterisk(table)
	t.ID = field.NewInt64(table, "id")
	t.Version = field.NewString(table, "version")
	t.AdminID = field.NewInt64(table, "admin_id")
	t.Username = field.NewString(table, "username")
	t.IP = field.NewString(table, "ip")
	t.UserAgent = field.NewString(table, "user_agent")
	t.Command = field.NewString(table, "command")
	t.Stdout = field.NewString(table, "stdout")
	t.Latency = field.NewInt64(table, "latency")
	t.CreatedAt = field.NewTime(table, "created_at")
	t.UpdatedAt = field.NewTime(table, "updated_at")

	t.fillFieldMap()

	return t
}

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

func (t *toolsRestartLog) fillFieldMap() {
	t.fieldMap = make(map[string]field.Expr, 11)
	t.fieldMap["id"] = t.ID
	t.fieldMap["version"] = t.Version
	t.fieldMap["admin_id"] = t.AdminID
	t.fieldMap["username"] = t.Username
	t.fieldMap["ip"] = t.IP
	t.fieldMap["user_agent"] = t.UserAgent
	t.fieldMap["command"] = t.Command
	t.fieldMap["stdout"] = t.Stdout
	t.fieldMap["latency"] = t.Latency
	t.fieldMap["created_at"] = t.CreatedAt
	t.fieldMap["updated_at"] = t.UpdatedAt
}

func (t toolsRestartLog) clone(db *gorm.DB) toolsRestartLog {
	t.toolsRestartLogDo.ReplaceConnPool(db.Statement.ConnPool)
	return t
}

func (t toolsRestartLog) replaceDB(db *gorm.DB) toolsRestartLog {
	t.toolsRestartLogDo.ReplaceDB(db)
	return t
}

type toolsRestartLogDo struct{ gen.DO }

func (t toolsRestartLogDo) Debug() *toolsRestartLogDo {
	return t.withDO(t.DO.Debug())
}

func (t toolsRestartLogDo) WithContext(ctx context.Context) *toolsRestartLogDo {
	return t.withDO(t.DO.WithContext(ctx))
}

func (t toolsRestartLogDo) ReadDB() *toolsRestartLogDo {
	return t.Clauses(dbresolver.Read)
}

func (t toolsRestartLogDo) WriteDB() *toolsRestartLogDo {
	return t.Clauses(dbresolver.Write)
}

func (t toolsRestartLogDo) Session(config *gorm.Session) *toolsRestartLogDo {
	return t.withDO(t.DO.Session(config))
}

func (t toolsRestartLogDo) Clauses(conds ...clause.Expression) *toolsRestartLogDo {
	return t.withDO(t.DO.Clauses(conds...))
}

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

func (t toolsRestartLogDo) Not(conds ...gen.Condition) *toolsRestartLogDo {
	return t.withDO(t.DO.Not(conds...))
}

func (t toolsRestartLogDo) Or(conds ...gen.Condition) *toolsRestartLogDo {
	return t.withDO(t.DO.Or(conds...))
}

func (t toolsRestartLogDo) Select(conds ...field.Expr) *toolsRestartLogDo {
	return t.withDO(t.DO.Select(conds...))
}

func (t toolsRestartLogDo) Where(conds ...gen.Condition) *toolsRestartLogDo {
	return t.withDO(t.DO.Where(conds...))
}

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

func (t toolsRestartLogDo) Order(conds ...field.Expr) *toolsRestartLogDo {
	return t.withDO(t.DO.Order(conds...))
}

func (t toolsRestartLogDo) Distinct(cols ...field.Expr) *toolsRestartLogDo {
	return t.withDO(t.DO.Distinct(cols...))
}

func (t toolsRestartLogDo) Omit(cols ...field.Expr) *toolsRestartLogDo {
	return t.withDO(t.DO.Omit(cols...))
}

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

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

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

func (t toolsRestartLogDo) Group(cols ...field.Expr) *toolsRestartLogDo {
	return t.withDO(t.DO.Group(cols...))
}

func (t toolsRestartLogDo) Having(conds ...gen.Condition) *toolsRestartLogDo {
	return t.withDO(t.DO.Having(conds...))
}

func (t toolsRestartLogDo) Limit(limit int) *toolsRestartLogDo {
	return t.withDO(t.DO.Limit(limit))
}

func (t toolsRestartLogDo) Offset(offset int) *toolsRestartLogDo {
	return t.withDO(t.DO.Offset(offset))
}

func (t toolsRestartLogDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *toolsRestartLogDo {
	return t.withDO(t.DO.Scopes(funcs...))
}

func (t toolsRestartLogDo) Unscoped() *toolsRestartLogDo {
	return t.withDO(t.DO.Unscoped())
}

func (t toolsRestartLogDo) Create(values ...*model.ToolsRestartLog) error {
	if len(values) == 0 {
		return nil
	}
	return t.DO.Create(values)
}

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

func (t toolsRestartLogDo) First() (*model.ToolsRestartLog, error) {
	if result, err := t.DO.First(); err != nil {
		return nil, err
	} else {
		return result.(*model.ToolsRestartLog), nil
	}
}

func (t toolsRestartLogDo) Take() (*model.ToolsRestartLog, error) {
	if result, err := t.DO.Take(); err != nil {
		return nil, err
	} else {
		return result.(*model.ToolsRestartLog), nil
	}
}

func (t toolsRestartLogDo) Last() (*model.ToolsRestartLog, error) {
	if result, err := t.DO.Last(); err != nil {
		return nil, err
	} else {
		return result.(*model.ToolsRestartLog), nil
	}
}

func (t toolsRestartLogDo) Find() ([]*model.ToolsRestartLog, error) {
	result, err := t.DO.Find()
	return result.([]*model.ToolsRestartLog), err
}

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

func (t toolsRestartLogDo) Attrs(attrs ...field.AssignExpr) *toolsRestartLogDo {
	return t.withDO(t.DO.Attrs(attrs...))
}

func (t toolsRestartLogDo) Assign(attrs ...field.AssignExpr) *toolsRestartLogDo {
	return t.withDO(t.DO.Assign(attrs...))
}

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

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

func (t toolsRestartLogDo) FirstOrInit() (*model.ToolsRestartLog, error) {
	if result, err := t.DO.FirstOrInit(); err != nil {
		return nil, err
	} else {
		return result.(*model.ToolsRestartLog), nil
	}
}

func (t toolsRestartLogDo) FirstOrCreate() (*model.ToolsRestartLog, error) {
	if result, err := t.DO.FirstOrCreate(); err != nil {
		return nil, err
	} else {
		return result.(*model.ToolsRestartLog), nil
	}
}

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

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

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

func (t toolsRestartLogDo) Scan(result interface{}) (err error) {
	return t.DO.Scan(result)
}

func (t toolsRestartLogDo) Delete(models ...*model.ToolsRestartLog) (result gen.ResultInfo, err error) {
	return t.DO.Delete(models)
}

func (t *toolsRestartLogDo) withDO(do gen.Dao) *toolsRestartLogDo {
	t.DO = *do.(*gen.DO)
	return t
}
