add default domain

This commit is contained in:
fancl 2024-12-13 09:31:31 +08:00
parent 4fd3d58ea0
commit 72d742a45d
1 changed files with 9 additions and 0 deletions

View File

@ -552,6 +552,9 @@ func CloneSchemas(ctx context.Context, db *gorm.DB, domain string) (err error) {
models []*types.Schema models []*types.Schema
) )
tx := db.WithContext(ctx) tx := db.WithContext(ctx)
if domain == "" {
domain = defaultDomain
}
if err = tx.Where("domain=?", defaultDomain).Find(&values).Error; err != nil { if err = tx.Where("domain=?", defaultDomain).Find(&values).Error; err != nil {
return fmt.Errorf("schema not found") return fmt.Errorf("schema not found")
} }
@ -608,6 +611,9 @@ func GetSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName
// VisibleSchemas 获取某个场景下面的schema // VisibleSchemas 获取某个场景下面的schema
func VisibleSchemas(ctx context.Context, db *gorm.DB, domain, moduleName, tableName, scenario string) ([]*types.Schema, error) { 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) schemas, err := GetSchemas(ctx, db, domain, moduleName, tableName)
if err != nil { if err != nil {
return nil, err return nil, err
@ -629,6 +635,9 @@ 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) { func ModelTypes(ctx context.Context, db *gorm.DB, model any, domainName, labelColumn, valueColumn string) (values []*types.TypeValue) {
tx := db.WithContext(ctx) tx := db.WithContext(ctx)
result := make([]map[string]any, 0, 10) result := make([]map[string]any, 0, 10)
if domainName == "" {
domainName = defaultDomain
}
tx.Model(model).Select(labelColumn, valueColumn).Where("domain=?", domainName).Scan(&result) tx.Model(model).Select(labelColumn, valueColumn).Where("domain=?", domainName).Scan(&result)
values = make([]*types.TypeValue, 0, len(result)) values = make([]*types.TypeValue, 0, len(result))
for _, pairs := range result { for _, pairs := range result {