linstrom/storage-new/dbgen/user_to_user_relations.gen.go

747 lines
21 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 dbgen
import (
"context"
"git.mstar.dev/mstar/linstrom/storage-new/models"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/schema"
"gorm.io/gen"
"gorm.io/gen/field"
"gorm.io/plugin/dbresolver"
)
func newUserToUserRelation(db *gorm.DB, opts ...gen.DOOption) userToUserRelation {
_userToUserRelation := userToUserRelation{}
_userToUserRelation.userToUserRelationDo.UseDB(db, opts...)
_userToUserRelation.userToUserRelationDo.UseModel(&models.UserToUserRelation{})
tableName := _userToUserRelation.userToUserRelationDo.TableName()
_userToUserRelation.ALL = field.NewAsterisk(tableName)
_userToUserRelation.ID = field.NewUint64(tableName, "id")
_userToUserRelation.UserId = field.NewString(tableName, "user_id")
_userToUserRelation.TargetUserId = field.NewString(tableName, "target_user_id")
_userToUserRelation.Relation = field.NewField(tableName, "relation")
_userToUserRelation.User = userToUserRelationBelongsToUser{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("User", "models.User"),
Icon: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Icon", "models.MediaMetadata"),
},
Background: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Background", "models.MediaMetadata"),
},
Banner: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Banner", "models.MediaMetadata"),
},
RemoteInfo: struct {
field.RelationField
User struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.RemoteInfo", "models.UserRemoteLinks"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.RemoteInfo.User", "models.User"),
},
},
InfoFields: struct {
field.RelationField
User struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.InfoFields", "models.UserInfoField"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.InfoFields.User", "models.User"),
},
},
BeingTypes: struct {
field.RelationField
User struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.BeingTypes", "models.UserToBeing"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.BeingTypes.User", "models.User"),
},
},
Tags: struct {
field.RelationField
User struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Tags", "models.UserToTag"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Tags.User", "models.User"),
},
},
Relations: struct {
field.RelationField
User struct {
field.RelationField
}
TargetUser struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Relations", "models.UserToUserRelation"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Relations.User", "models.User"),
},
TargetUser: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Relations.TargetUser", "models.User"),
},
},
Pronouns: struct {
field.RelationField
User struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Pronouns", "models.UserToPronoun"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Pronouns.User", "models.User"),
},
},
Roles: struct {
field.RelationField
User struct {
field.RelationField
}
Role struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.Roles", "models.UserToRole"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Roles.User", "models.User"),
},
Role: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.Roles.Role", "models.Role"),
},
},
AuthMethods: struct {
field.RelationField
User struct {
field.RelationField
}
}{
RelationField: field.NewRelation("User.AuthMethods", "models.UserAuthMethod"),
User: struct {
field.RelationField
}{
RelationField: field.NewRelation("User.AuthMethods.User", "models.User"),
},
},
}
_userToUserRelation.TargetUser = userToUserRelationBelongsToTargetUser{
db: db.Session(&gorm.Session{}),
RelationField: field.NewRelation("TargetUser", "models.User"),
}
_userToUserRelation.fillFieldMap()
return _userToUserRelation
}
type userToUserRelation struct {
userToUserRelationDo
ALL field.Asterisk
ID field.Uint64
UserId field.String
TargetUserId field.String
Relation field.Field
User userToUserRelationBelongsToUser
TargetUser userToUserRelationBelongsToTargetUser
fieldMap map[string]field.Expr
}
func (u userToUserRelation) Table(newTableName string) *userToUserRelation {
u.userToUserRelationDo.UseTable(newTableName)
return u.updateTableName(newTableName)
}
func (u userToUserRelation) As(alias string) *userToUserRelation {
u.userToUserRelationDo.DO = *(u.userToUserRelationDo.As(alias).(*gen.DO))
return u.updateTableName(alias)
}
func (u *userToUserRelation) updateTableName(table string) *userToUserRelation {
u.ALL = field.NewAsterisk(table)
u.ID = field.NewUint64(table, "id")
u.UserId = field.NewString(table, "user_id")
u.TargetUserId = field.NewString(table, "target_user_id")
u.Relation = field.NewField(table, "relation")
u.fillFieldMap()
return u
}
func (u *userToUserRelation) 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 *userToUserRelation) fillFieldMap() {
u.fieldMap = make(map[string]field.Expr, 6)
u.fieldMap["id"] = u.ID
u.fieldMap["user_id"] = u.UserId
u.fieldMap["target_user_id"] = u.TargetUserId
u.fieldMap["relation"] = u.Relation
}
func (u userToUserRelation) clone(db *gorm.DB) userToUserRelation {
u.userToUserRelationDo.ReplaceConnPool(db.Statement.ConnPool)
return u
}
func (u userToUserRelation) replaceDB(db *gorm.DB) userToUserRelation {
u.userToUserRelationDo.ReplaceDB(db)
return u
}
type userToUserRelationBelongsToUser struct {
db *gorm.DB
field.RelationField
Icon struct {
field.RelationField
}
Background struct {
field.RelationField
}
Banner struct {
field.RelationField
}
RemoteInfo struct {
field.RelationField
User struct {
field.RelationField
}
}
InfoFields struct {
field.RelationField
User struct {
field.RelationField
}
}
BeingTypes struct {
field.RelationField
User struct {
field.RelationField
}
}
Tags struct {
field.RelationField
User struct {
field.RelationField
}
}
Relations struct {
field.RelationField
User struct {
field.RelationField
}
TargetUser struct {
field.RelationField
}
}
Pronouns struct {
field.RelationField
User struct {
field.RelationField
}
}
Roles struct {
field.RelationField
User struct {
field.RelationField
}
Role struct {
field.RelationField
}
}
AuthMethods struct {
field.RelationField
User struct {
field.RelationField
}
}
}
func (a userToUserRelationBelongsToUser) Where(conds ...field.Expr) *userToUserRelationBelongsToUser {
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 userToUserRelationBelongsToUser) WithContext(ctx context.Context) *userToUserRelationBelongsToUser {
a.db = a.db.WithContext(ctx)
return &a
}
func (a userToUserRelationBelongsToUser) Session(session *gorm.Session) *userToUserRelationBelongsToUser {
a.db = a.db.Session(session)
return &a
}
func (a userToUserRelationBelongsToUser) Model(m *models.UserToUserRelation) *userToUserRelationBelongsToUserTx {
return &userToUserRelationBelongsToUserTx{a.db.Model(m).Association(a.Name())}
}
type userToUserRelationBelongsToUserTx struct{ tx *gorm.Association }
func (a userToUserRelationBelongsToUserTx) Find() (result *models.User, err error) {
return result, a.tx.Find(&result)
}
func (a userToUserRelationBelongsToUserTx) Append(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a userToUserRelationBelongsToUserTx) Replace(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a userToUserRelationBelongsToUserTx) Delete(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a userToUserRelationBelongsToUserTx) Clear() error {
return a.tx.Clear()
}
func (a userToUserRelationBelongsToUserTx) Count() int64 {
return a.tx.Count()
}
type userToUserRelationBelongsToTargetUser struct {
db *gorm.DB
field.RelationField
}
func (a userToUserRelationBelongsToTargetUser) Where(conds ...field.Expr) *userToUserRelationBelongsToTargetUser {
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 userToUserRelationBelongsToTargetUser) WithContext(ctx context.Context) *userToUserRelationBelongsToTargetUser {
a.db = a.db.WithContext(ctx)
return &a
}
func (a userToUserRelationBelongsToTargetUser) Session(session *gorm.Session) *userToUserRelationBelongsToTargetUser {
a.db = a.db.Session(session)
return &a
}
func (a userToUserRelationBelongsToTargetUser) Model(m *models.UserToUserRelation) *userToUserRelationBelongsToTargetUserTx {
return &userToUserRelationBelongsToTargetUserTx{a.db.Model(m).Association(a.Name())}
}
type userToUserRelationBelongsToTargetUserTx struct{ tx *gorm.Association }
func (a userToUserRelationBelongsToTargetUserTx) Find() (result *models.User, err error) {
return result, a.tx.Find(&result)
}
func (a userToUserRelationBelongsToTargetUserTx) Append(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Append(targetValues...)
}
func (a userToUserRelationBelongsToTargetUserTx) Replace(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Replace(targetValues...)
}
func (a userToUserRelationBelongsToTargetUserTx) Delete(values ...*models.User) (err error) {
targetValues := make([]interface{}, len(values))
for i, v := range values {
targetValues[i] = v
}
return a.tx.Delete(targetValues...)
}
func (a userToUserRelationBelongsToTargetUserTx) Clear() error {
return a.tx.Clear()
}
func (a userToUserRelationBelongsToTargetUserTx) Count() int64 {
return a.tx.Count()
}
type userToUserRelationDo struct{ gen.DO }
type IUserToUserRelationDo interface {
gen.SubQuery
Debug() IUserToUserRelationDo
WithContext(ctx context.Context) IUserToUserRelationDo
WithResult(fc func(tx gen.Dao)) gen.ResultInfo
ReplaceDB(db *gorm.DB)
ReadDB() IUserToUserRelationDo
WriteDB() IUserToUserRelationDo
As(alias string) gen.Dao
Session(config *gorm.Session) IUserToUserRelationDo
Columns(cols ...field.Expr) gen.Columns
Clauses(conds ...clause.Expression) IUserToUserRelationDo
Not(conds ...gen.Condition) IUserToUserRelationDo
Or(conds ...gen.Condition) IUserToUserRelationDo
Select(conds ...field.Expr) IUserToUserRelationDo
Where(conds ...gen.Condition) IUserToUserRelationDo
Order(conds ...field.Expr) IUserToUserRelationDo
Distinct(cols ...field.Expr) IUserToUserRelationDo
Omit(cols ...field.Expr) IUserToUserRelationDo
Join(table schema.Tabler, on ...field.Expr) IUserToUserRelationDo
LeftJoin(table schema.Tabler, on ...field.Expr) IUserToUserRelationDo
RightJoin(table schema.Tabler, on ...field.Expr) IUserToUserRelationDo
Group(cols ...field.Expr) IUserToUserRelationDo
Having(conds ...gen.Condition) IUserToUserRelationDo
Limit(limit int) IUserToUserRelationDo
Offset(offset int) IUserToUserRelationDo
Count() (count int64, err error)
Scopes(funcs ...func(gen.Dao) gen.Dao) IUserToUserRelationDo
Unscoped() IUserToUserRelationDo
Create(values ...*models.UserToUserRelation) error
CreateInBatches(values []*models.UserToUserRelation, batchSize int) error
Save(values ...*models.UserToUserRelation) error
First() (*models.UserToUserRelation, error)
Take() (*models.UserToUserRelation, error)
Last() (*models.UserToUserRelation, error)
Find() ([]*models.UserToUserRelation, error)
FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserToUserRelation, err error)
FindInBatches(result *[]*models.UserToUserRelation, batchSize int, fc func(tx gen.Dao, batch int) error) error
Pluck(column field.Expr, dest interface{}) error
Delete(...*models.UserToUserRelation) (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) IUserToUserRelationDo
Assign(attrs ...field.AssignExpr) IUserToUserRelationDo
Joins(fields ...field.RelationField) IUserToUserRelationDo
Preload(fields ...field.RelationField) IUserToUserRelationDo
FirstOrInit() (*models.UserToUserRelation, error)
FirstOrCreate() (*models.UserToUserRelation, error)
FindByPage(offset int, limit int) (result []*models.UserToUserRelation, 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) IUserToUserRelationDo
UnderlyingDB() *gorm.DB
schema.Tabler
}
func (u userToUserRelationDo) Debug() IUserToUserRelationDo {
return u.withDO(u.DO.Debug())
}
func (u userToUserRelationDo) WithContext(ctx context.Context) IUserToUserRelationDo {
return u.withDO(u.DO.WithContext(ctx))
}
func (u userToUserRelationDo) ReadDB() IUserToUserRelationDo {
return u.Clauses(dbresolver.Read)
}
func (u userToUserRelationDo) WriteDB() IUserToUserRelationDo {
return u.Clauses(dbresolver.Write)
}
func (u userToUserRelationDo) Session(config *gorm.Session) IUserToUserRelationDo {
return u.withDO(u.DO.Session(config))
}
func (u userToUserRelationDo) Clauses(conds ...clause.Expression) IUserToUserRelationDo {
return u.withDO(u.DO.Clauses(conds...))
}
func (u userToUserRelationDo) Returning(value interface{}, columns ...string) IUserToUserRelationDo {
return u.withDO(u.DO.Returning(value, columns...))
}
func (u userToUserRelationDo) Not(conds ...gen.Condition) IUserToUserRelationDo {
return u.withDO(u.DO.Not(conds...))
}
func (u userToUserRelationDo) Or(conds ...gen.Condition) IUserToUserRelationDo {
return u.withDO(u.DO.Or(conds...))
}
func (u userToUserRelationDo) Select(conds ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.Select(conds...))
}
func (u userToUserRelationDo) Where(conds ...gen.Condition) IUserToUserRelationDo {
return u.withDO(u.DO.Where(conds...))
}
func (u userToUserRelationDo) Order(conds ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.Order(conds...))
}
func (u userToUserRelationDo) Distinct(cols ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.Distinct(cols...))
}
func (u userToUserRelationDo) Omit(cols ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.Omit(cols...))
}
func (u userToUserRelationDo) Join(table schema.Tabler, on ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.Join(table, on...))
}
func (u userToUserRelationDo) LeftJoin(table schema.Tabler, on ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.LeftJoin(table, on...))
}
func (u userToUserRelationDo) RightJoin(table schema.Tabler, on ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.RightJoin(table, on...))
}
func (u userToUserRelationDo) Group(cols ...field.Expr) IUserToUserRelationDo {
return u.withDO(u.DO.Group(cols...))
}
func (u userToUserRelationDo) Having(conds ...gen.Condition) IUserToUserRelationDo {
return u.withDO(u.DO.Having(conds...))
}
func (u userToUserRelationDo) Limit(limit int) IUserToUserRelationDo {
return u.withDO(u.DO.Limit(limit))
}
func (u userToUserRelationDo) Offset(offset int) IUserToUserRelationDo {
return u.withDO(u.DO.Offset(offset))
}
func (u userToUserRelationDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IUserToUserRelationDo {
return u.withDO(u.DO.Scopes(funcs...))
}
func (u userToUserRelationDo) Unscoped() IUserToUserRelationDo {
return u.withDO(u.DO.Unscoped())
}
func (u userToUserRelationDo) Create(values ...*models.UserToUserRelation) error {
if len(values) == 0 {
return nil
}
return u.DO.Create(values)
}
func (u userToUserRelationDo) CreateInBatches(values []*models.UserToUserRelation, 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 userToUserRelationDo) Save(values ...*models.UserToUserRelation) error {
if len(values) == 0 {
return nil
}
return u.DO.Save(values)
}
func (u userToUserRelationDo) First() (*models.UserToUserRelation, error) {
if result, err := u.DO.First(); err != nil {
return nil, err
} else {
return result.(*models.UserToUserRelation), nil
}
}
func (u userToUserRelationDo) Take() (*models.UserToUserRelation, error) {
if result, err := u.DO.Take(); err != nil {
return nil, err
} else {
return result.(*models.UserToUserRelation), nil
}
}
func (u userToUserRelationDo) Last() (*models.UserToUserRelation, error) {
if result, err := u.DO.Last(); err != nil {
return nil, err
} else {
return result.(*models.UserToUserRelation), nil
}
}
func (u userToUserRelationDo) Find() ([]*models.UserToUserRelation, error) {
result, err := u.DO.Find()
return result.([]*models.UserToUserRelation), err
}
func (u userToUserRelationDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*models.UserToUserRelation, err error) {
buf := make([]*models.UserToUserRelation, 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 userToUserRelationDo) FindInBatches(result *[]*models.UserToUserRelation, batchSize int, fc func(tx gen.Dao, batch int) error) error {
return u.DO.FindInBatches(result, batchSize, fc)
}
func (u userToUserRelationDo) Attrs(attrs ...field.AssignExpr) IUserToUserRelationDo {
return u.withDO(u.DO.Attrs(attrs...))
}
func (u userToUserRelationDo) Assign(attrs ...field.AssignExpr) IUserToUserRelationDo {
return u.withDO(u.DO.Assign(attrs...))
}
func (u userToUserRelationDo) Joins(fields ...field.RelationField) IUserToUserRelationDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Joins(_f))
}
return &u
}
func (u userToUserRelationDo) Preload(fields ...field.RelationField) IUserToUserRelationDo {
for _, _f := range fields {
u = *u.withDO(u.DO.Preload(_f))
}
return &u
}
func (u userToUserRelationDo) FirstOrInit() (*models.UserToUserRelation, error) {
if result, err := u.DO.FirstOrInit(); err != nil {
return nil, err
} else {
return result.(*models.UserToUserRelation), nil
}
}
func (u userToUserRelationDo) FirstOrCreate() (*models.UserToUserRelation, error) {
if result, err := u.DO.FirstOrCreate(); err != nil {
return nil, err
} else {
return result.(*models.UserToUserRelation), nil
}
}
func (u userToUserRelationDo) FindByPage(offset int, limit int) (result []*models.UserToUserRelation, 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 userToUserRelationDo) 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 userToUserRelationDo) Scan(result interface{}) (err error) {
return u.DO.Scan(result)
}
func (u userToUserRelationDo) Delete(models ...*models.UserToUserRelation) (result gen.ResultInfo, err error) {
return u.DO.Delete(models)
}
func (u *userToUserRelationDo) withDO(do gen.Dao) *userToUserRelationDo {
u.DO = *do.(*gen.DO)
return u
}