395 lines
11 KiB
Go
395 lines
11 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 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"
|
|
|
|
"atom/database/models"
|
|
)
|
|
|
|
func newUserRole(db *gorm.DB, opts ...gen.DOOption) userRole {
|
|
_userRole := userRole{}
|
|
|
|
_userRole.userRoleDo.UseDB(db, opts...)
|
|
_userRole.userRoleDo.UseModel(&models.UserRole{})
|
|
|
|
tableName := _userRole.userRoleDo.TableName()
|
|
_userRole.ALL = field.NewAsterisk(tableName)
|
|
_userRole.UserID = field.NewUint64(tableName, "user_id")
|
|
_userRole.RoleID = field.NewUint64(tableName, "role_id")
|
|
|
|
_userRole.fillFieldMap()
|
|
|
|
return _userRole
|
|
}
|
|
|
|
type userRole struct {
|
|
userRoleDo userRoleDo
|
|
|
|
ALL field.Asterisk
|
|
UserID field.Uint64
|
|
RoleID field.Uint64
|
|
|
|
fieldMap map[string]field.Expr
|
|
}
|
|
|
|
func (u userRole) Table(newTableName string) *userRole {
|
|
u.userRoleDo.UseTable(newTableName)
|
|
return u.updateTableName(newTableName)
|
|
}
|
|
|
|
func (u userRole) As(alias string) *userRole {
|
|
u.userRoleDo.DO = *(u.userRoleDo.As(alias).(*gen.DO))
|
|
return u.updateTableName(alias)
|
|
}
|
|
|
|
func (u *userRole) updateTableName(table string) *userRole {
|
|
u.ALL = field.NewAsterisk(table)
|
|
u.UserID = field.NewUint64(table, "user_id")
|
|
u.RoleID = field.NewUint64(table, "role_id")
|
|
|
|
u.fillFieldMap()
|
|
|
|
return u
|
|
}
|
|
|
|
func (u *userRole) WithContext(ctx context.Context) IUserRoleDo { return u.userRoleDo.WithContext(ctx) }
|
|
|
|
func (u userRole) TableName() string { return u.userRoleDo.TableName() }
|
|
|
|
func (u userRole) Alias() string { return u.userRoleDo.Alias() }
|
|
|
|
func (u *userRole) 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 *userRole) fillFieldMap() {
|
|
u.fieldMap = make(map[string]field.Expr, 2)
|
|
u.fieldMap["user_id"] = u.UserID
|
|
u.fieldMap["role_id"] = u.RoleID
|
|
}
|
|
|
|
func (u userRole) clone(db *gorm.DB) userRole {
|
|
u.userRoleDo.ReplaceConnPool(db.Statement.ConnPool)
|
|
return u
|
|
}
|
|
|
|
func (u userRole) replaceDB(db *gorm.DB) userRole {
|
|
u.userRoleDo.ReplaceDB(db)
|
|
return u
|
|
}
|
|
|
|
type userRoleDo struct{ gen.DO }
|
|
|
|
type IUserRoleDo interface {
|
|
gen.SubQuery
|
|
Debug() IUserRoleDo
|
|
WithContext(ctx context.Context) IUserRoleDo
|
|
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
|
|
ReplaceDB(db *gorm.DB)
|
|
ReadDB() IUserRoleDo
|
|
WriteDB() IUserRoleDo
|
|
As(alias string) gen.Dao
|
|
Session(config *gorm.Session) IUserRoleDo
|
|
Columns(cols ...field.Expr) gen.Columns
|
|
Clauses(conds ...clause.Expression) IUserRoleDo
|
|
Not(conds ...gen.Condition) IUserRoleDo
|
|
Or(conds ...gen.Condition) IUserRoleDo
|
|
Select(conds ...field.Expr) IUserRoleDo
|
|
Where(conds ...gen.Condition) IUserRoleDo
|
|
Order(conds ...field.Expr) IUserRoleDo
|
|
Distinct(cols ...field.Expr) IUserRoleDo
|
|
Omit(cols ...field.Expr) IUserRoleDo
|
|
Join(table schema.Tabler, on ...field.Expr) IUserRoleDo
|
|
LeftJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo
|
|
RightJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo
|
|
Group(cols ...field.Expr) IUserRoleDo
|
|
Having(conds ...gen.Condition) IUserRoleDo
|
|
Limit(limit int) IUserRoleDo
|
|
Offset(offset int) IUserRoleDo
|
|
Count() (count int64, err error)
|
|
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserRoleDo
|
|
Unscoped() IUserRoleDo
|
|
Create(values ...*models.UserRole) error
|
|
CreateInBatches(values []*models.UserRole, batchSize int) error
|
|
Save(values ...*models.UserRole) error
|
|
First() (*models.UserRole, error)
|
|
Take() (*models.UserRole, error)
|
|
Last() (*models.UserRole, error)
|
|
Find() ([]*models.UserRole, error)
|
|
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserRole, err error)
|
|
FindInBatches(result *[]*models.UserRole, batchSize int, fc func(tx gen.Dao, batch int) error) error
|
|
Pluck(column field.Expr, dest interface{}) error
|
|
Delete(...*models.UserRole) (info gen.ResultInfo, err error)
|
|
Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
Updates(value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
|
|
UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
|
|
UpdateFrom(q gen.SubQuery) gen.Dao
|
|
Attrs(attrs ...field.AssignExpr) IUserRoleDo
|
|
Assign(attrs ...field.AssignExpr) IUserRoleDo
|
|
Joins(fields ...field.RelationField) IUserRoleDo
|
|
Preload(fields ...field.RelationField) IUserRoleDo
|
|
FirstOrInit() (*models.UserRole, error)
|
|
FirstOrCreate() (*models.UserRole, error)
|
|
FindByPage(offset int, limit int) (result []*models.UserRole, count int64, err error)
|
|
ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
|
|
Scan(result interface{}) (err error)
|
|
Returning(value interface{}, columns ...string) IUserRoleDo
|
|
UnderlyingDB() *gorm.DB
|
|
schema.Tabler
|
|
}
|
|
|
|
func (u userRoleDo) Debug() IUserRoleDo {
|
|
return u.withDO(u.DO.Debug())
|
|
}
|
|
|
|
func (u userRoleDo) WithContext(ctx context.Context) IUserRoleDo {
|
|
return u.withDO(u.DO.WithContext(ctx))
|
|
}
|
|
|
|
func (u userRoleDo) ReadDB() IUserRoleDo {
|
|
return u.Clauses(dbresolver.Read)
|
|
}
|
|
|
|
func (u userRoleDo) WriteDB() IUserRoleDo {
|
|
return u.Clauses(dbresolver.Write)
|
|
}
|
|
|
|
func (u userRoleDo) Session(config *gorm.Session) IUserRoleDo {
|
|
return u.withDO(u.DO.Session(config))
|
|
}
|
|
|
|
func (u userRoleDo) Clauses(conds ...clause.Expression) IUserRoleDo {
|
|
return u.withDO(u.DO.Clauses(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Returning(value interface{}, columns ...string) IUserRoleDo {
|
|
return u.withDO(u.DO.Returning(value, columns...))
|
|
}
|
|
|
|
func (u userRoleDo) Not(conds ...gen.Condition) IUserRoleDo {
|
|
return u.withDO(u.DO.Not(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Or(conds ...gen.Condition) IUserRoleDo {
|
|
return u.withDO(u.DO.Or(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Select(conds ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.Select(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Where(conds ...gen.Condition) IUserRoleDo {
|
|
return u.withDO(u.DO.Where(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IUserRoleDo {
|
|
return u.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
|
|
}
|
|
|
|
func (u userRoleDo) Order(conds ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.Order(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Distinct(cols ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.Distinct(cols...))
|
|
}
|
|
|
|
func (u userRoleDo) Omit(cols ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.Omit(cols...))
|
|
}
|
|
|
|
func (u userRoleDo) Join(table schema.Tabler, on ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.Join(table, on...))
|
|
}
|
|
|
|
func (u userRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.LeftJoin(table, on...))
|
|
}
|
|
|
|
func (u userRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.RightJoin(table, on...))
|
|
}
|
|
|
|
func (u userRoleDo) Group(cols ...field.Expr) IUserRoleDo {
|
|
return u.withDO(u.DO.Group(cols...))
|
|
}
|
|
|
|
func (u userRoleDo) Having(conds ...gen.Condition) IUserRoleDo {
|
|
return u.withDO(u.DO.Having(conds...))
|
|
}
|
|
|
|
func (u userRoleDo) Limit(limit int) IUserRoleDo {
|
|
return u.withDO(u.DO.Limit(limit))
|
|
}
|
|
|
|
func (u userRoleDo) Offset(offset int) IUserRoleDo {
|
|
return u.withDO(u.DO.Offset(offset))
|
|
}
|
|
|
|
func (u userRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserRoleDo {
|
|
return u.withDO(u.DO.Scopes(funcs...))
|
|
}
|
|
|
|
func (u userRoleDo) Unscoped() IUserRoleDo {
|
|
return u.withDO(u.DO.Unscoped())
|
|
}
|
|
|
|
func (u userRoleDo) Create(values ...*models.UserRole) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return u.DO.Create(values)
|
|
}
|
|
|
|
func (u userRoleDo) CreateInBatches(values []*models.UserRole, 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 userRoleDo) Save(values ...*models.UserRole) error {
|
|
if len(values) == 0 {
|
|
return nil
|
|
}
|
|
return u.DO.Save(values)
|
|
}
|
|
|
|
func (u userRoleDo) First() (*models.UserRole, error) {
|
|
if result, err := u.DO.First(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRole), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleDo) Take() (*models.UserRole, error) {
|
|
if result, err := u.DO.Take(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRole), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleDo) Last() (*models.UserRole, error) {
|
|
if result, err := u.DO.Last(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRole), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleDo) Find() ([]*models.UserRole, error) {
|
|
result, err := u.DO.Find()
|
|
return result.([]*models.UserRole), err
|
|
}
|
|
|
|
func (u userRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserRole, err error) {
|
|
buf := make([]*models.UserRole, 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 userRoleDo) FindInBatches(result *[]*models.UserRole, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
|
return u.DO.FindInBatches(result, batchSize, fc)
|
|
}
|
|
|
|
func (u userRoleDo) Attrs(attrs ...field.AssignExpr) IUserRoleDo {
|
|
return u.withDO(u.DO.Attrs(attrs...))
|
|
}
|
|
|
|
func (u userRoleDo) Assign(attrs ...field.AssignExpr) IUserRoleDo {
|
|
return u.withDO(u.DO.Assign(attrs...))
|
|
}
|
|
|
|
func (u userRoleDo) Joins(fields ...field.RelationField) IUserRoleDo {
|
|
for _, _f := range fields {
|
|
u = *u.withDO(u.DO.Joins(_f))
|
|
}
|
|
return &u
|
|
}
|
|
|
|
func (u userRoleDo) Preload(fields ...field.RelationField) IUserRoleDo {
|
|
for _, _f := range fields {
|
|
u = *u.withDO(u.DO.Preload(_f))
|
|
}
|
|
return &u
|
|
}
|
|
|
|
func (u userRoleDo) FirstOrInit() (*models.UserRole, error) {
|
|
if result, err := u.DO.FirstOrInit(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRole), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleDo) FirstOrCreate() (*models.UserRole, error) {
|
|
if result, err := u.DO.FirstOrCreate(); err != nil {
|
|
return nil, err
|
|
} else {
|
|
return result.(*models.UserRole), nil
|
|
}
|
|
}
|
|
|
|
func (u userRoleDo) FindByPage(offset int, limit int) (result []*models.UserRole, 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 userRoleDo) 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 userRoleDo) Scan(result interface{}) (err error) {
|
|
return u.DO.Scan(result)
|
|
}
|
|
|
|
func (u userRoleDo) Delete(models ...*models.UserRole) (result gen.ResultInfo, err error) {
|
|
return u.DO.Delete(models)
|
|
}
|
|
|
|
func (u *userRoleDo) withDO(do gen.Dao) *userRoleDo {
|
|
u.DO = *do.(*gen.DO)
|
|
return u
|
|
}
|