Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
fancl | 68bdabddee | |
fancl | 72d742a45d | |
fancl | 4fd3d58ea0 |
|
@ -15,7 +15,7 @@ func (identity *Identify) Name() string {
|
|||
}
|
||||
|
||||
func (identity *Identify) Initialize(db *gorm.DB) (err error) {
|
||||
err = db.Callback().Create().Before("gorm:create").Register("auto_identified", identity.Grant)
|
||||
err = db.Callback().Create().Before("gorm:create").Register("rest_auto_identified", identity.Grant)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -121,10 +121,10 @@ func (validate *Validate) findRule(name string, rules []*validateRule) *validate
|
|||
|
||||
func (validate *Validate) Initialize(db *gorm.DB) (err error) {
|
||||
validate.validator = validator.New()
|
||||
if err = db.Callback().Create().Before("gorm:before_create").Register("model_validate", validate.Validate); err != nil {
|
||||
if err = db.Callback().Create().Before("gorm:before_create").Register("rest_validate_create", validate.Validate); err != nil {
|
||||
return
|
||||
}
|
||||
if err = db.Callback().Create().Before("gorm:before_update").Register("model_validate", validate.Validate); err != nil {
|
||||
if err = db.Callback().Create().Before("gorm:before_update").Register("rest_validate_update", validate.Validate); err != nil {
|
||||
return
|
||||
}
|
||||
if err = validate.validator.RegisterValidationCtx("telephone", validate.telephoneValidate); err != nil {
|
||||
|
|
12
rest.go
12
rest.go
|
@ -552,6 +552,9 @@ func CloneSchemas(ctx context.Context, db *gorm.DB, domain string) (err error) {
|
|||
models []*types.Schema
|
||||
)
|
||||
tx := db.WithContext(ctx)
|
||||
if domain == "" {
|
||||
domain = defaultDomain
|
||||
}
|
||||
if err = tx.Where("domain=?", defaultDomain).Find(&values).Error; err != nil {
|
||||
return fmt.Errorf("schema not found")
|
||||
}
|
||||
|
@ -608,6 +611,9 @@ func GetSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName
|
|||
|
||||
// VisibleSchemas 获取某个场景下面的schema
|
||||
func VisibleSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName, scenario string) ([]*types.Schema, error) {
|
||||
if domain == "" {
|
||||
domain = defaultDomain
|
||||
}
|
||||
schemas, err := GetSchemas(ctx, db, domain, moduleName, tableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -629,7 +635,11 @@ func VisibleSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableN
|
|||
func ModelTypes(ctx context.Context, db *gorm.DB, model any, domainName, labelColumn, valueColumn string) (values []*types.TypeValue) {
|
||||
tx := db.WithContext(ctx)
|
||||
result := make([]map[string]any, 0, 10)
|
||||
tx.Model(model).Select(labelColumn, valueColumn).Where("domain=?", domainName).Scan(&result)
|
||||
if domainName == "" {
|
||||
tx.Model(model).Select(labelColumn, valueColumn).Scan(&result)
|
||||
} else {
|
||||
tx.Model(model).Select(labelColumn, valueColumn).Where("domain=?", domainName).Scan(&result)
|
||||
}
|
||||
values = make([]*types.TypeValue, 0, len(result))
|
||||
for _, pairs := range result {
|
||||
feed := &types.TypeValue{}
|
||||
|
|
Loading…
Reference in New Issue