tenant: add invites and join requests
This commit is contained in:
@@ -35,18 +35,18 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) userQuery {
|
||||
_userQuery.Status = field.NewField(tableName, "status")
|
||||
_userQuery.Metas = field.NewJSONB(tableName, "metas")
|
||||
_userQuery.VerifiedAt = field.NewTime(tableName, "verified_at")
|
||||
_userQuery.Tenants = userQueryManyToManyTenants{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tenants", "Tenant"),
|
||||
}
|
||||
|
||||
_userQuery.OwnedTenant = userQueryBelongsToOwnedTenant{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("OwnedTenant", "Tenant"),
|
||||
}
|
||||
|
||||
_userQuery.Tenants = userQueryManyToManyTenants{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tenants", "Tenant"),
|
||||
}
|
||||
|
||||
_userQuery.fillFieldMap()
|
||||
|
||||
return _userQuery
|
||||
@@ -55,21 +55,21 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) userQuery {
|
||||
type userQuery struct {
|
||||
userQueryDo userQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Username field.String
|
||||
Password field.String
|
||||
Roles field.Array
|
||||
Status field.Field
|
||||
Metas field.JSONB
|
||||
VerifiedAt field.Time
|
||||
Tenants userQueryManyToManyTenants
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Username field.String
|
||||
Password field.String
|
||||
Roles field.Array
|
||||
Status field.Field
|
||||
Metas field.JSONB
|
||||
VerifiedAt field.Time
|
||||
OwnedTenant userQueryBelongsToOwnedTenant
|
||||
|
||||
Tenants userQueryManyToManyTenants
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -141,101 +141,20 @@ func (u *userQuery) fillFieldMap() {
|
||||
|
||||
func (u userQuery) clone(db *gorm.DB) userQuery {
|
||||
u.userQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
u.Tenants.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.Tenants.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
u.OwnedTenant.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.OwnedTenant.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
u.Tenants.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.Tenants.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return u
|
||||
}
|
||||
|
||||
func (u userQuery) replaceDB(db *gorm.DB) userQuery {
|
||||
u.userQueryDo.ReplaceDB(db)
|
||||
u.Tenants.db = db.Session(&gorm.Session{})
|
||||
u.OwnedTenant.db = db.Session(&gorm.Session{})
|
||||
u.Tenants.db = db.Session(&gorm.Session{})
|
||||
return u
|
||||
}
|
||||
|
||||
type userQueryManyToManyTenants struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Where(conds ...field.Expr) *userQueryManyToManyTenants {
|
||||
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 userQueryManyToManyTenants) WithContext(ctx context.Context) *userQueryManyToManyTenants {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Session(session *gorm.Session) *userQueryManyToManyTenants {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Model(m *User) *userQueryManyToManyTenantsTx {
|
||||
return &userQueryManyToManyTenantsTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Unscoped() *userQueryManyToManyTenants {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryManyToManyTenantsTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Find() (result []*Tenant, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Append(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Replace(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Delete(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Unscoped() *userQueryManyToManyTenantsTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenant struct {
|
||||
db *gorm.DB
|
||||
|
||||
@@ -317,6 +236,87 @@ func (a userQueryBelongsToOwnedTenantTx) Unscoped() *userQueryBelongsToOwnedTena
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryManyToManyTenants struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Where(conds ...field.Expr) *userQueryManyToManyTenants {
|
||||
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 userQueryManyToManyTenants) WithContext(ctx context.Context) *userQueryManyToManyTenants {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Session(session *gorm.Session) *userQueryManyToManyTenants {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Model(m *User) *userQueryManyToManyTenantsTx {
|
||||
return &userQueryManyToManyTenantsTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenants) Unscoped() *userQueryManyToManyTenants {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryManyToManyTenantsTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Find() (result []*Tenant, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Append(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Replace(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Delete(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a userQueryManyToManyTenantsTx) Unscoped() *userQueryManyToManyTenantsTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryDo struct{ gen.DO }
|
||||
|
||||
func (u userQueryDo) Debug() *userQueryDo {
|
||||
|
||||
Reference in New Issue
Block a user