491 lines
13 KiB
Go
491 lines
13 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 newUser(db *gorm.DB, opts ...gen.DOOption) user {
|
|
_user := user{}
|
|
|
|
_user.userDo.UseDB(db, opts...)
|
|
_user.userDo.UseModel(&models.User{})
|
|
|
|
tableName := _user.userDo.TableName()
|
|
_user.ALL = field.NewAsterisk(tableName)
|
|
_user.ID = field.NewInt32(tableName, "id")
|
|
_user.CreatedAt = field.NewTime(tableName, "created_at")
|
|
_user.UpdatedAt = field.NewTime(tableName, "updated_at")
|
|
_user.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
_user.AdminID = field.NewInt32(tableName, "admin_id")
|
|
_user.Phone = field.NewString(tableName, "phone")
|
|
_user.Username = field.NewString(tableName, "username")
|
|
_user.Email = field.NewString(tableName, "email")
|
|
_user.Password = field.NewString(tableName, "password")
|
|
_user.Name = field.NewString(tableName, "name")
|
|
_user.Avatar = field.NewString(tableName, "avatar")
|
|
_user.Status = field.NewInt(tableName, "status")
|
|
_user.Balance = field.NewField(tableName, "balance")
|
|
_user.IDType = field.NewInt(tableName, "id_type")
|
|
_user.IDNo = field.NewString(tableName, "id_no")
|
|
_user.IDToken = field.NewString(tableName, "id_token")
|
|
_user.ContactQQ = field.NewString(tableName, "contact_qq")
|
|
_user.ContactWechat = field.NewString(tableName, "contact_wechat")
|
|
_user.LastLogin = field.NewTime(tableName, "last_login")
|
|
_user.LastLoginIP = field.NewField(tableName, "last_login_ip")
|
|
_user.LastLoginUA = field.NewString(tableName, "last_login_ua")
|
|
_user.Admin = userBelongsToAdmin{
|
|
db: db.Session(&gorm.Session{}),
|
|
|
|
RelationField: field.NewRelation("Admin", "models.Admin"),
|
|
}
|
|
|
|
_user.fillFieldMap()
|
|
|
|
return _user
|
|
}
|
|
|
|
type user struct {
|
|
userDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32
|
|
CreatedAt field.Time
|
|
UpdatedAt field.Time
|
|
DeletedAt field.Field
|
|
AdminID field.Int32
|
|
Phone field.String
|
|
Username field.String
|
|
Email field.String
|
|
Password field.String
|
|
Name field.String
|
|
Avatar field.String
|
|
Status field.Int
|
|
Balance field.Field
|
|
IDType field.Int
|
|
IDNo field.String
|
|
IDToken field.String
|
|
ContactQQ field.String
|
|
ContactWechat field.String
|
|
LastLogin field.Time
|
|
LastLoginIP field.Field
|
|
LastLoginUA field.String
|
|
Admin userBelongsToAdmin
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (u user) Table(newTableName string) *user {
|
|
u.userDo.UseTable(newTableName)
|
|
return u.updateTableName(newTableName)
|
|
}
|
|
|
|
func (u user) As(alias string) *user {
|
|
u.userDo.DO = *(u.userDo.As(alias).(*gen.DO))
|
|
return u.updateTableName(alias)
|
|
}
|
|
|
|
func (u *user) updateTableName(table string) *user {
|
|
u.ALL = field.NewAsterisk(table)
|
|
u.ID = field.NewInt32(table, "id")
|
|
u.CreatedAt = field.NewTime(table, "created_at")
|
|
u.UpdatedAt = field.NewTime(table, "updated_at")
|
|
u.DeletedAt = field.NewField(table, "deleted_at")
|
|
u.AdminID = field.NewInt32(table, "admin_id")
|
|
u.Phone = field.NewString(table, "phone")
|
|
u.Username = field.NewString(table, "username")
|
|
u.Email = field.NewString(table, "email")
|
|
u.Password = field.NewString(table, "password")
|
|
u.Name = field.NewString(table, "name")
|
|
u.Avatar = field.NewString(table, "avatar")
|
|
u.Status = field.NewInt(table, "status")
|
|
u.Balance = field.NewField(table, "balance")
|
|
u.IDType = field.NewInt(table, "id_type")
|
|
u.IDNo = field.NewString(table, "id_no")
|
|
u.IDToken = field.NewString(table, "id_token")
|
|
u.ContactQQ = field.NewString(table, "contact_qq")
|
|
u.ContactWechat = field.NewString(table, "contact_wechat")
|
|
u.LastLogin = field.NewTime(table, "last_login")
|
|
u.LastLoginIP = field.NewField(table, "last_login_ip")
|
|
u.LastLoginUA = field.NewString(table, "last_login_ua")
|
|
|
|
u.fillFieldMap()
|
|
|
|
return u
|
|
}
|
|
|
|
func (u *user) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
|
_f, ok := u.fieldMap[fieldName]
|
|
if !ok || _f == nil {
|
|
return nil, false
|
|
}
|
|
_oe, ok := _f.(field.OrderExpr)
|
|
return _oe, ok
|
|
}
|
|
|
|
func (u *user) fillFieldMap() {
|
|
u.fieldMap = make(map[string]field.Expr, 22)
|
|
u.fieldMap["id"] = u.ID
|
|
u.fieldMap["created_at"] = u.CreatedAt
|
|
u.fieldMap["updated_at"] = u.UpdatedAt
|
|
u.fieldMap["deleted_at"] = u.DeletedAt
|
|
u.fieldMap["admin_id"] = u.AdminID
|
|
u.fieldMap["phone"] = u.Phone
|
|
u.fieldMap["username"] = u.Username
|
|
u.fieldMap["email"] = u.Email
|
|
u.fieldMap["password"] = u.Password
|
|
u.fieldMap["name"] = u.Name
|
|
u.fieldMap["avatar"] = u.Avatar
|
|
u.fieldMap["status"] = u.Status
|
|
u.fieldMap["balance"] = u.Balance
|
|
u.fieldMap["id_type"] = u.IDType
|
|
u.fieldMap["id_no"] = u.IDNo
|
|
u.fieldMap["id_token"] = u.IDToken
|
|
u.fieldMap["contact_qq"] = u.ContactQQ
|
|
u.fieldMap["contact_wechat"] = u.ContactWechat
|
|
u.fieldMap["last_login"] = u.LastLogin
|
|
u.fieldMap["last_login_ip"] = u.LastLoginIP
|
|
u.fieldMap["last_login_ua"] = u.LastLoginUA
|
|
|
|
}
|
|
|
|
func (u user) clone(db *gorm.DB) user {
|
|
u.userDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
u.Admin.db = db.Session(&gorm.Session{Initialized: true})
|
|
u.Admin.db.Statement.ConnPool = db.Statement.ConnPool
|
|
return u
|
|
}
|
|
|
|
func (u user) replaceDB(db *gorm.DB) user {
|
|
u.userDo.ReplaceDB(db)
|
|
u.Admin.db = db.Session(&gorm.Session{})
|
|
return u
|
|
}
|
|
|
|
type userBelongsToAdmin struct {
|
|
db *gorm.DB
|
|
|
|
field.RelationField
|
|
}
|
|
|
|
func (a userBelongsToAdmin) Where(conds ...field.Expr) *userBelongsToAdmin {
|
|
if len(conds) == 0 {
|
|
return &a
|
|
}
|
|
|
|
exprs := make([]clause.Expression, 0, len(conds))
|
|
for _, cond := range conds {
|
|
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
|
}
|
|
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
|
return &a
|
|
}
|
|
|
|
func (a userBelongsToAdmin) WithContext(ctx context.Context) *userBelongsToAdmin {
|
|
a.db = a.db.WithContext(ctx)
|
|
return &a
|
|
}
|
|
|
|
func (a userBelongsToAdmin) Session(session *gorm.Session) *userBelongsToAdmin {
|
|
a.db = a.db.Session(session)
|
|
return &a
|
|
}
|
|
|
|
func (a userBelongsToAdmin) Model(m *models.User) *userBelongsToAdminTx {
|
|
return &userBelongsToAdminTx{a.db.Model(m).Association(a.Name())}
|
|
}
|
|
|
|
func (a userBelongsToAdmin) Unscoped() *userBelongsToAdmin {
|
|
a.db = a.db.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type userBelongsToAdminTx struct{ tx *gorm.Association }
|
|
|
|
func (a userBelongsToAdminTx) Find() (result *models.Admin, err error) {
|
|
return result, a.tx.Find(&result)
|
|
}
|
|
|
|
func (a userBelongsToAdminTx) Append(values ...*models.Admin) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Append(targetValues...)
|
|
}
|
|
|
|
func (a userBelongsToAdminTx) Replace(values ...*models.Admin) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Replace(targetValues...)
|
|
}
|
|
|
|
func (a userBelongsToAdminTx) Delete(values ...*models.Admin) (err error) {
|
|
targetValues := make([]interface{}, len(values))
|
|
for i, v := range values {
|
|
targetValues[i] = v
|
|
}
|
|
return a.tx.Delete(targetValues...)
|
|
}
|
|
|
|
func (a userBelongsToAdminTx) Clear() error {
|
|
return a.tx.Clear()
|
|
}
|
|
|
|
func (a userBelongsToAdminTx) Count() int64 {
|
|
return a.tx.Count()
|
|
}
|
|
|
|
func (a userBelongsToAdminTx) Unscoped() *userBelongsToAdminTx {
|
|
a.tx = a.tx.Unscoped()
|
|
return &a
|
|
}
|
|
|
|
type userDo struct{ gen.DO }
|
|
|
|
func (u userDo) Debug() *userDo {
|
|
return u.withDO(u.DO.Debug())
|
|
}
|
|
|
|
func (u userDo) WithContext(ctx context.Context) *userDo {
|
|
return u.withDO(u.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (u userDo) ReadDB() *userDo {
|
|
return u.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (u userDo) WriteDB() *userDo {
|
|
return u.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (u userDo) Session(config *gorm.Session) *userDo {
|
|
return u.withDO(u.DO.Session(config))
|
|
}
|
|
|
|
func (u userDo) Clauses(conds ...clause.Expression) *userDo {
|
|
return u.withDO(u.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (u userDo) Returning(value interface{}, columns ...string) *userDo {
|
|
return u.withDO(u.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (u userDo) Not(conds ...gen.Condition) *userDo {
|
|
return u.withDO(u.DO.Not(conds...))
|
|
}
|
|
|
|
func (u userDo) Or(conds ...gen.Condition) *userDo {
|
|
return u.withDO(u.DO.Or(conds...))
|
|
}
|
|
|
|
func (u userDo) Select(conds ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.Select(conds...))
|
|
}
|
|
|
|
func (u userDo) Where(conds ...gen.Condition) *userDo {
|
|
return u.withDO(u.DO.Where(conds...))
|
|
}
|
|
|
|
func (u userDo) Order(conds ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.Order(conds...))
|
|
}
|
|
|
|
func (u userDo) Distinct(cols ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (u userDo) Omit(cols ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.Omit(cols...))
|
|
}
|
|
|
|
func (u userDo) Join(table schema.Tabler, on ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.Join(table, on...))
|
|
}
|
|
|
|
func (u userDo) LeftJoin(table schema.Tabler, on ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (u userDo) RightJoin(table schema.Tabler, on ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (u userDo) Group(cols ...field.Expr) *userDo {
|
|
return u.withDO(u.DO.Group(cols...))
|
|
}
|
|
|
|
func (u userDo) Having(conds ...gen.Condition) *userDo {
|
|
return u.withDO(u.DO.Having(conds...))
|
|
}
|
|
|
|
func (u userDo) Limit(limit int) *userDo {
|
|
return u.withDO(u.DO.Limit(limit))
|
|
}
|
|
|
|
func (u userDo) Offset(offset int) *userDo {
|
|
return u.withDO(u.DO.Offset(offset))
|
|
}
|
|
|
|
func (u userDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *userDo {
|
|
return u.withDO(u.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (u userDo) Unscoped() *userDo {
|
|
return u.withDO(u.DO.Unscoped())
|
|
}
|
|
|
|
func (u userDo) Create(values ...*models.User) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return u.DO.Create(values)
|
|
}
|
|
|
|
func (u userDo) CreateInBatches(values []*models.User, batchSize int) error {
|
|
return u.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 (u userDo) Save(values ...*models.User) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return u.DO.Save(values)
|
|
}
|
|
|
|
func (u userDo) First() (*models.User, error) {
|
|
if result, err := u.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.User), nil
|
|
}
|
|
}
|
|
|
|
func (u userDo) Take() (*models.User, error) {
|
|
if result, err := u.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.User), nil
|
|
}
|
|
}
|
|
|
|
func (u userDo) Last() (*models.User, error) {
|
|
if result, err := u.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.User), nil
|
|
}
|
|
}
|
|
|
|
func (u userDo) Find() ([]*models.User, error) {
|
|
result, err := u.DO.Find()
|
|
return result.([]*models.User), err
|
|
}
|
|
|
|
func (u userDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.User, err error) {
|
|
buf := make([]*models.User, 0, batchSize)
|
|
err = u.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 (u userDo) FindInBatches(result *[]*models.User, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return u.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (u userDo) Attrs(attrs ...field.AssignExpr) *userDo {
|
|
return u.withDO(u.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (u userDo) Assign(attrs ...field.AssignExpr) *userDo {
|
|
return u.withDO(u.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (u userDo) Joins(fields ...field.RelationField) *userDo {
|
|
for _, _f := range fields {
|
|
u = *u.withDO(u.DO.Joins(_f))
|
|
}
|
|
return &u
|
|
}
|
|
|
|
func (u userDo) Preload(fields ...field.RelationField) *userDo {
|
|
for _, _f := range fields {
|
|
u = *u.withDO(u.DO.Preload(_f))
|
|
}
|
|
return &u
|
|
}
|
|
|
|
func (u userDo) FirstOrInit() (*models.User, error) {
|
|
if result, err := u.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.User), nil
|
|
}
|
|
}
|
|
|
|
func (u userDo) FirstOrCreate() (*models.User, error) {
|
|
if result, err := u.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.User), nil
|
|
}
|
|
}
|
|
|
|
func (u userDo) FindByPage(offset int, limit int) (result []*models.User, count int64, err error) {
|
|
result, err = u.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 = u.Offset(-1).Limit(-1).Count()
|
|
return
|
|
}
|
|
|
|
func (u userDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
|
count, err = u.Count()
|
|
if err != nil {
|
|
return
|
|
}
|
|
|
|
err = u.Offset(offset).Limit(limit).Scan(result)
|
|
return
|
|
}
|
|
|
|
func (u userDo) Scan(result interface{}) (err error) {
|
|
return u.DO.Scan(result)
|
|
}
|
|
|
|
func (u userDo) Delete(models ...*models.User) (result gen.ResultInfo, err error) {
|
|
return u.DO.Delete(models)
|
|
}
|
|
|
|
func (u *userDo) withDO(do gen.Dao) *userDo {
|
|
u.DO = *do.(*gen.DO)
|
|
return u
|
|
}
|