344 lines
8.8 KiB
Go
344 lines
8.8 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 queries
|
|
|
|
import (
|
|
"context"
|
|
|
|
"gorm.io/gorm"
|
|
"gorm.io/gorm/clause"
|
|
"gorm.io/gorm/schema"
|
|
|
|
"gorm.io/gen"
|
|
"gorm.io/gen/field"
|
|
|
|
"gorm.io/plugin/dbresolver"
|
|
|
|
"platform/web/models"
|
|
)
|
|
|
|
func newWhitelist(db *gorm.DB, opts ...gen.DOOption) whitelist {
|
|
_whitelist := whitelist{}
|
|
|
|
_whitelist.whitelistDo.UseDB(db, opts...)
|
|
_whitelist.whitelistDo.UseModel(&models.Whitelist{})
|
|
|
|
tableName := _whitelist.whitelistDo.TableName()
|
|
_whitelist.ALL = field.NewAsterisk(tableName)
|
|
_whitelist.ID = field.NewInt32(tableName, "id")
|
|
_whitelist.UserID = field.NewInt32(tableName, "user_id")
|
|
_whitelist.Host = field.NewString(tableName, "host")
|
|
_whitelist.CreatedAt = field.NewField(tableName, "created_at")
|
|
_whitelist.UpdatedAt = field.NewField(tableName, "updated_at")
|
|
_whitelist.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
_whitelist.Remark = field.NewString(tableName, "remark")
|
|
|
|
_whitelist.fillFieldMap()
|
|
|
|
return _whitelist
|
|
}
|
|
|
|
type whitelist struct {
|
|
whitelistDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32 // 白名单ID
|
|
UserID field.Int32 // 用户ID
|
|
Host field.String // IP地址
|
|
CreatedAt field.Field // 创建时间
|
|
UpdatedAt field.Field // 更新时间
|
|
DeletedAt field.Field // 删除时间
|
|
Remark field.String // 备注
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (w whitelist) Table(newTableName string) *whitelist {
|
|
w.whitelistDo.UseTable(newTableName)
|
|
return w.updateTableName(newTableName)
|
|
}
|
|
|
|
func (w whitelist) As(alias string) *whitelist {
|
|
w.whitelistDo.DO = *(w.whitelistDo.As(alias).(*gen.DO))
|
|
return w.updateTableName(alias)
|
|
}
|
|
|
|
func (w *whitelist) updateTableName(table string) *whitelist {
|
|
w.ALL = field.NewAsterisk(table)
|
|
w.ID = field.NewInt32(table, "id")
|
|
w.UserID = field.NewInt32(table, "user_id")
|
|
w.Host = field.NewString(table, "host")
|
|
w.CreatedAt = field.NewField(table, "created_at")
|
|
w.UpdatedAt = field.NewField(table, "updated_at")
|
|
w.DeletedAt = field.NewField(table, "deleted_at")
|
|
w.Remark = field.NewString(table, "remark")
|
|
|
|
w.fillFieldMap()
|
|
|
|
return w
|
|
}
|
|
|
|
func (w *whitelist) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := w.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (w *whitelist) fillFieldMap() {
|
|
w.fieldMap = make(map[string]field.Expr, 7)
|
|
w.fieldMap["id"] = w.ID
|
|
w.fieldMap["user_id"] = w.UserID
|
|
w.fieldMap["host"] = w.Host
|
|
w.fieldMap["created_at"] = w.CreatedAt
|
|
w.fieldMap["updated_at"] = w.UpdatedAt
|
|
w.fieldMap["deleted_at"] = w.DeletedAt
|
|
w.fieldMap["remark"] = w.Remark
|
|
}
|
|
|
|
func (w whitelist) clone(db *gorm.DB) whitelist {
|
|
w.whitelistDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return w
|
|
}
|
|
|
|
func (w whitelist) replaceDB(db *gorm.DB) whitelist {
|
|
w.whitelistDo.ReplaceDB(db)
|
|
return w
|
|
}
|
|
|
|
type whitelistDo struct{ gen.DO }
|
|
|
|
func (w whitelistDo) Debug() *whitelistDo {
|
|
return w.withDO(w.DO.Debug())
|
|
}
|
|
|
|
func (w whitelistDo) WithContext(ctx context.Context) *whitelistDo {
|
|
return w.withDO(w.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (w whitelistDo) ReadDB() *whitelistDo {
|
|
return w.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (w whitelistDo) WriteDB() *whitelistDo {
|
|
return w.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (w whitelistDo) Session(config *gorm.Session) *whitelistDo {
|
|
return w.withDO(w.DO.Session(config))
|
|
}
|
|
|
|
func (w whitelistDo) Clauses(conds ...clause.Expression) *whitelistDo {
|
|
return w.withDO(w.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Returning(value interface{}, columns ...string) *whitelistDo {
|
|
return w.withDO(w.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (w whitelistDo) Not(conds ...gen.Condition) *whitelistDo {
|
|
return w.withDO(w.DO.Not(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Or(conds ...gen.Condition) *whitelistDo {
|
|
return w.withDO(w.DO.Or(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Select(conds ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.Select(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Where(conds ...gen.Condition) *whitelistDo {
|
|
return w.withDO(w.DO.Where(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Order(conds ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.Order(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Distinct(cols ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (w whitelistDo) Omit(cols ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.Omit(cols...))
|
|
}
|
|
|
|
func (w whitelistDo) Join(table schema.Tabler, on ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.Join(table, on...))
|
|
}
|
|
|
|
func (w whitelistDo) LeftJoin(table schema.Tabler, on ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (w whitelistDo) RightJoin(table schema.Tabler, on ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (w whitelistDo) Group(cols ...field.Expr) *whitelistDo {
|
|
return w.withDO(w.DO.Group(cols...))
|
|
}
|
|
|
|
func (w whitelistDo) Having(conds ...gen.Condition) *whitelistDo {
|
|
return w.withDO(w.DO.Having(conds...))
|
|
}
|
|
|
|
func (w whitelistDo) Limit(limit int) *whitelistDo {
|
|
return w.withDO(w.DO.Limit(limit))
|
|
}
|
|
|
|
func (w whitelistDo) Offset(offset int) *whitelistDo {
|
|
return w.withDO(w.DO.Offset(offset))
|
|
}
|
|
|
|
func (w whitelistDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *whitelistDo {
|
|
return w.withDO(w.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (w whitelistDo) Unscoped() *whitelistDo {
|
|
return w.withDO(w.DO.Unscoped())
|
|
}
|
|
|
|
func (w whitelistDo) Create(values ...*models.Whitelist) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return w.DO.Create(values)
|
|
}
|
|
|
|
func (w whitelistDo) CreateInBatches(values []*models.Whitelist, batchSize int) error {
|
|
return w.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 (w whitelistDo) Save(values ...*models.Whitelist) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return w.DO.Save(values)
|
|
}
|
|
|
|
func (w whitelistDo) First() (*models.Whitelist, error) {
|
|
if result, err := w.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Whitelist), nil
|
|
}
|
|
}
|
|
|
|
func (w whitelistDo) Take() (*models.Whitelist, error) {
|
|
if result, err := w.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Whitelist), nil
|
|
}
|
|
}
|
|
|
|
func (w whitelistDo) Last() (*models.Whitelist, error) {
|
|
if result, err := w.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Whitelist), nil
|
|
}
|
|
}
|
|
|
|
func (w whitelistDo) Find() ([]*models.Whitelist, error) {
|
|
result, err := w.DO.Find()
|
|
return result.([]*models.Whitelist), err
|
|
}
|
|
|
|
func (w whitelistDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.Whitelist, err error) {
|
|
buf := make([]*models.Whitelist, 0, batchSize)
|
|
err = w.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 (w whitelistDo) FindInBatches(result *[]*models.Whitelist, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return w.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (w whitelistDo) Attrs(attrs ...field.AssignExpr) *whitelistDo {
|
|
return w.withDO(w.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (w whitelistDo) Assign(attrs ...field.AssignExpr) *whitelistDo {
|
|
return w.withDO(w.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (w whitelistDo) Joins(fields ...field.RelationField) *whitelistDo {
|
|
for _, _f := range fields {
|
|
w = *w.withDO(w.DO.Joins(_f))
|
|
}
|
|
return &w
|
|
}
|
|
|
|
func (w whitelistDo) Preload(fields ...field.RelationField) *whitelistDo {
|
|
for _, _f := range fields {
|
|
w = *w.withDO(w.DO.Preload(_f))
|
|
}
|
|
return &w
|
|
}
|
|
|
|
func (w whitelistDo) FirstOrInit() (*models.Whitelist, error) {
|
|
if result, err := w.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Whitelist), nil
|
|
}
|
|
}
|
|
|
|
func (w whitelistDo) FirstOrCreate() (*models.Whitelist, error) {
|
|
if result, err := w.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.Whitelist), nil
|
|
}
|
|
}
|
|
|
|
func (w whitelistDo) FindByPage(offset int, limit int) (result []*models.Whitelist, count int64, err error) {
|
|
result, err = w.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 = w.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (w whitelistDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = w.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = w.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (w whitelistDo) Scan(result interface{}) (err error) {
|
|
return w.DO.Scan(result)
|
|
}
|
|
|
|
func (w whitelistDo) Delete(models ...*models.Whitelist) (result gen.ResultInfo, err error) {
|
|
return w.DO.Delete(models)
|
|
}
|
|
|
|
func (w *whitelistDo) withDO(do gen.Dao) *whitelistDo {
|
|
w.DO = *do.(*gen.DO)
|
|
return w
|
|
}
|