340 lines
9.0 KiB
Go
340 lines
9.0 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 newUserRoleLink(db *gorm.DB, opts ...gen.DOOption) userRoleLink {
|
|
_userRoleLink := userRoleLink{}
|
|
|
|
_userRoleLink.userRoleLinkDo.UseDB(db, opts...)
|
|
_userRoleLink.userRoleLinkDo.UseModel(&models.UserRoleLink{})
|
|
|
|
tableName := _userRoleLink.userRoleLinkDo.TableName()
|
|
_userRoleLink.ALL = field.NewAsterisk(tableName)
|
|
_userRoleLink.ID = field.NewInt32(tableName, "id")
|
|
_userRoleLink.UserID = field.NewInt32(tableName, "user_id")
|
|
_userRoleLink.RoleID = field.NewInt32(tableName, "role_id")
|
|
_userRoleLink.CreatedAt = field.NewField(tableName, "created_at")
|
|
_userRoleLink.UpdatedAt = field.NewField(tableName, "updated_at")
|
|
_userRoleLink.DeletedAt = field.NewField(tableName, "deleted_at")
|
|
|
|
_userRoleLink.fillFieldMap()
|
|
|
|
return _userRoleLink
|
|
}
|
|
|
|
type userRoleLink struct {
|
|
userRoleLinkDo
|
|
|
|
ALL field.Asterisk
|
|
ID field.Int32 // 关联ID
|
|
UserID field.Int32 // 用户ID
|
|
RoleID field.Int32 // 角色ID
|
|
CreatedAt field.Field // 创建时间
|
|
UpdatedAt field.Field // 更新时间
|
|
DeletedAt field.Field // 删除时间
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (u userRoleLink) Table(newTableName string) *userRoleLink {
|
|
u.userRoleLinkDo.UseTable(newTableName)
|
|
return u.updateTableName(newTableName)
|
|
}
|
|
|
|
func (u userRoleLink) As(alias string) *userRoleLink {
|
|
u.userRoleLinkDo.DO = *(u.userRoleLinkDo.As(alias).(*gen.DO))
|
|
return u.updateTableName(alias)
|
|
}
|
|
|
|
func (u *userRoleLink) updateTableName(table string) *userRoleLink {
|
|
u.ALL = field.NewAsterisk(table)
|
|
u.ID = field.NewInt32(table, "id")
|
|
u.UserID = field.NewInt32(table, "user_id")
|
|
u.RoleID = field.NewInt32(table, "role_id")
|
|
u.CreatedAt = field.NewField(table, "created_at")
|
|
u.UpdatedAt = field.NewField(table, "updated_at")
|
|
u.DeletedAt = field.NewField(table, "deleted_at")
|
|
|
|
u.fillFieldMap()
|
|
|
|
return u
|
|
}
|
|
|
|
func (u *userRoleLink) 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 *userRoleLink) fillFieldMap() {
|
|
u.fieldMap = make(map[string]field.Expr, 6)
|
|
u.fieldMap["id"] = u.ID
|
|
u.fieldMap["user_id"] = u.UserID
|
|
u.fieldMap["role_id"] = u.RoleID
|
|
u.fieldMap["created_at"] = u.CreatedAt
|
|
u.fieldMap["updated_at"] = u.UpdatedAt
|
|
u.fieldMap["deleted_at"] = u.DeletedAt
|
|
}
|
|
|
|
func (u userRoleLink) clone(db *gorm.DB) userRoleLink {
|
|
u.userRoleLinkDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return u
|
|
}
|
|
|
|
func (u userRoleLink) replaceDB(db *gorm.DB) userRoleLink {
|
|
u.userRoleLinkDo.ReplaceDB(db)
|
|
return u
|
|
}
|
|
|
|
type userRoleLinkDo struct{ gen.DO }
|
|
|
|
func (u userRoleLinkDo) Debug() *userRoleLinkDo {
|
|
return u.withDO(u.DO.Debug())
|
|
}
|
|
|
|
func (u userRoleLinkDo) WithContext(ctx context.Context) *userRoleLinkDo {
|
|
return u.withDO(u.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (u userRoleLinkDo) ReadDB() *userRoleLinkDo {
|
|
return u.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (u userRoleLinkDo) WriteDB() *userRoleLinkDo {
|
|
return u.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (u userRoleLinkDo) Session(config *gorm.Session) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Session(config))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Clauses(conds ...clause.Expression) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Returning(value interface{}, columns ...string) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Not(conds ...gen.Condition) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Not(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Or(conds ...gen.Condition) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Or(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Select(conds ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Select(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Where(conds ...gen.Condition) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Where(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Order(conds ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Order(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Distinct(cols ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Omit(cols ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Omit(cols...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Join(table schema.Tabler, on ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Join(table, on...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) LeftJoin(table schema.Tabler, on ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) RightJoin(table schema.Tabler, on ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Group(cols ...field.Expr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Group(cols...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Having(conds ...gen.Condition) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Having(conds...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Limit(limit int) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Limit(limit))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Offset(offset int) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Offset(offset))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Unscoped() *userRoleLinkDo {
|
|
return u.withDO(u.DO.Unscoped())
|
|
}
|
|
|
|
func (u userRoleLinkDo) Create(values ...*models.UserRoleLink) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return u.DO.Create(values)
|
|
}
|
|
|
|
func (u userRoleLinkDo) CreateInBatches(values []*models.UserRoleLink, 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 userRoleLinkDo) Save(values ...*models.UserRoleLink) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return u.DO.Save(values)
|
|
}
|
|
|
|
func (u userRoleLinkDo) First() (*models.UserRoleLink, error) {
|
|
if result, err := u.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRoleLink), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleLinkDo) Take() (*models.UserRoleLink, error) {
|
|
if result, err := u.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRoleLink), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleLinkDo) Last() (*models.UserRoleLink, error) {
|
|
if result, err := u.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRoleLink), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleLinkDo) Find() ([]*models.UserRoleLink, error) {
|
|
result, err := u.DO.Find()
|
|
return result.([]*models.UserRoleLink), err
|
|
}
|
|
|
|
func (u userRoleLinkDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserRoleLink, err error) {
|
|
buf := make([]*models.UserRoleLink, 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 userRoleLinkDo) FindInBatches(result *[]*models.UserRoleLink, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return u.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (u userRoleLinkDo) Attrs(attrs ...field.AssignExpr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Assign(attrs ...field.AssignExpr) *userRoleLinkDo {
|
|
return u.withDO(u.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (u userRoleLinkDo) Joins(fields ...field.RelationField) *userRoleLinkDo {
|
|
for _, _f := range fields {
|
|
u = *u.withDO(u.DO.Joins(_f))
|
|
}
|
|
return &u
|
|
}
|
|
|
|
func (u userRoleLinkDo) Preload(fields ...field.RelationField) *userRoleLinkDo {
|
|
for _, _f := range fields {
|
|
u = *u.withDO(u.DO.Preload(_f))
|
|
}
|
|
return &u
|
|
}
|
|
|
|
func (u userRoleLinkDo) FirstOrInit() (*models.UserRoleLink, error) {
|
|
if result, err := u.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRoleLink), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleLinkDo) FirstOrCreate() (*models.UserRoleLink, error) {
|
|
if result, err := u.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRoleLink), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleLinkDo) FindByPage(offset int, limit int) (result []*models.UserRoleLink, 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 userRoleLinkDo) 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 userRoleLinkDo) Scan(result interface{}) (err error) {
|
|
return u.DO.Scan(result)
|
|
}
|
|
|
|
func (u userRoleLinkDo) Delete(models ...*models.UserRoleLink) (result gen.ResultInfo, err error) {
|
|
return u.DO.Delete(models)
|
|
}
|
|
|
|
func (u *userRoleLinkDo) withDO(do gen.Dao) *userRoleLinkDo {
|
|
u.DO = *do.(*gen.DO)
|
|
return u
|
|
}
|