feat: implement new structure
This commit is contained in:
@@ -26,28 +26,26 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) userQuery {
|
||||
tableName := _userQuery.userQueryDo.TableName()
|
||||
_userQuery.ALL = field.NewAsterisk(tableName)
|
||||
_userQuery.ID = field.NewInt64(tableName, "id")
|
||||
_userQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_userQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_userQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
_userQuery.Username = field.NewString(tableName, "username")
|
||||
_userQuery.Password = field.NewString(tableName, "password")
|
||||
_userQuery.Roles = field.NewArray(tableName, "roles")
|
||||
_userQuery.Status = field.NewField(tableName, "status")
|
||||
_userQuery.Status = field.NewString(tableName, "status")
|
||||
_userQuery.Metas = field.NewJSONB(tableName, "metas")
|
||||
_userQuery.Balance = field.NewInt64(tableName, "balance")
|
||||
_userQuery.BalanceFrozen = field.NewInt64(tableName, "balance_frozen")
|
||||
_userQuery.VerifiedAt = field.NewTime(tableName, "verified_at")
|
||||
_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.Nickname = field.NewString(tableName, "nickname")
|
||||
_userQuery.Avatar = field.NewString(tableName, "avatar")
|
||||
_userQuery.Gender = field.NewString(tableName, "gender")
|
||||
_userQuery.Bio = field.NewString(tableName, "bio")
|
||||
_userQuery.Birthday = field.NewField(tableName, "birthday")
|
||||
_userQuery.Location = field.NewJSONB(tableName, "location")
|
||||
_userQuery.Points = field.NewInt64(tableName, "points")
|
||||
_userQuery.Phone = field.NewString(tableName, "phone")
|
||||
_userQuery.IsRealNameVerified = field.NewBool(tableName, "is_real_name_verified")
|
||||
_userQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_userQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_userQuery.DeletedAt = field.NewField(tableName, "deleted_at")
|
||||
|
||||
_userQuery.fillFieldMap()
|
||||
|
||||
@@ -57,22 +55,28 @@ 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
|
||||
Balance field.Int64 // 全局可用余额:分/最小货币单位;用户在所有已加入租户内共享该余额;默认 0
|
||||
BalanceFrozen field.Int64 // 全局冻结余额:分/最小货币单位;用于下单冻结等;默认 0
|
||||
VerifiedAt field.Time
|
||||
OwnedTenant userQueryBelongsToOwnedTenant
|
||||
|
||||
Tenants userQueryManyToManyTenants
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
Username field.String
|
||||
Password field.String
|
||||
Roles field.Array
|
||||
Status field.String
|
||||
Metas field.JSONB
|
||||
Balance field.Int64
|
||||
BalanceFrozen field.Int64
|
||||
VerifiedAt field.Time
|
||||
Nickname field.String
|
||||
Avatar field.String
|
||||
Gender field.String
|
||||
Bio field.String
|
||||
Birthday field.Field
|
||||
Location field.JSONB
|
||||
Points field.Int64
|
||||
Phone field.String
|
||||
IsRealNameVerified field.Bool
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -90,17 +94,26 @@ func (u userQuery) As(alias string) *userQuery {
|
||||
func (u *userQuery) updateTableName(table string) *userQuery {
|
||||
u.ALL = field.NewAsterisk(table)
|
||||
u.ID = field.NewInt64(table, "id")
|
||||
u.CreatedAt = field.NewTime(table, "created_at")
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
u.DeletedAt = field.NewField(table, "deleted_at")
|
||||
u.Username = field.NewString(table, "username")
|
||||
u.Password = field.NewString(table, "password")
|
||||
u.Roles = field.NewArray(table, "roles")
|
||||
u.Status = field.NewField(table, "status")
|
||||
u.Status = field.NewString(table, "status")
|
||||
u.Metas = field.NewJSONB(table, "metas")
|
||||
u.Balance = field.NewInt64(table, "balance")
|
||||
u.BalanceFrozen = field.NewInt64(table, "balance_frozen")
|
||||
u.VerifiedAt = field.NewTime(table, "verified_at")
|
||||
u.Nickname = field.NewString(table, "nickname")
|
||||
u.Avatar = field.NewString(table, "avatar")
|
||||
u.Gender = field.NewString(table, "gender")
|
||||
u.Bio = field.NewString(table, "bio")
|
||||
u.Birthday = field.NewField(table, "birthday")
|
||||
u.Location = field.NewJSONB(table, "location")
|
||||
u.Points = field.NewInt64(table, "points")
|
||||
u.Phone = field.NewString(table, "phone")
|
||||
u.IsRealNameVerified = field.NewBool(table, "is_real_name_verified")
|
||||
u.CreatedAt = field.NewTime(table, "created_at")
|
||||
u.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
u.DeletedAt = field.NewField(table, "deleted_at")
|
||||
|
||||
u.fillFieldMap()
|
||||
|
||||
@@ -131,11 +144,8 @@ func (u *userQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
}
|
||||
|
||||
func (u *userQuery) fillFieldMap() {
|
||||
u.fieldMap = make(map[string]field.Expr, 14)
|
||||
u.fieldMap = make(map[string]field.Expr, 21)
|
||||
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["username"] = u.Username
|
||||
u.fieldMap["password"] = u.Password
|
||||
u.fieldMap["roles"] = u.Roles
|
||||
@@ -144,187 +154,30 @@ func (u *userQuery) fillFieldMap() {
|
||||
u.fieldMap["balance"] = u.Balance
|
||||
u.fieldMap["balance_frozen"] = u.BalanceFrozen
|
||||
u.fieldMap["verified_at"] = u.VerifiedAt
|
||||
|
||||
u.fieldMap["nickname"] = u.Nickname
|
||||
u.fieldMap["avatar"] = u.Avatar
|
||||
u.fieldMap["gender"] = u.Gender
|
||||
u.fieldMap["bio"] = u.Bio
|
||||
u.fieldMap["birthday"] = u.Birthday
|
||||
u.fieldMap["location"] = u.Location
|
||||
u.fieldMap["points"] = u.Points
|
||||
u.fieldMap["phone"] = u.Phone
|
||||
u.fieldMap["is_real_name_verified"] = u.IsRealNameVerified
|
||||
u.fieldMap["created_at"] = u.CreatedAt
|
||||
u.fieldMap["updated_at"] = u.UpdatedAt
|
||||
u.fieldMap["deleted_at"] = u.DeletedAt
|
||||
}
|
||||
|
||||
func (u userQuery) clone(db *gorm.DB) userQuery {
|
||||
u.userQueryDo.ReplaceConnPool(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.OwnedTenant.db = db.Session(&gorm.Session{})
|
||||
u.Tenants.db = db.Session(&gorm.Session{})
|
||||
return u
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenant struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Where(conds ...field.Expr) *userQueryBelongsToOwnedTenant {
|
||||
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 userQueryBelongsToOwnedTenant) WithContext(ctx context.Context) *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Session(session *gorm.Session) *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Model(m *User) *userQueryBelongsToOwnedTenantTx {
|
||||
return &userQueryBelongsToOwnedTenantTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Unscoped() *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenantTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Find() (result *Tenant, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) 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 userQueryBelongsToOwnedTenantTx) 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 userQueryBelongsToOwnedTenantTx) 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 userQueryBelongsToOwnedTenantTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Unscoped() *userQueryBelongsToOwnedTenantTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
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