fix: 修改远程数据库列表查询规则 (#2166)

This commit is contained in:
ssongliu 2023-09-04 14:20:13 +08:00 committed by GitHub
parent ba38402a24
commit ecc444db9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -101,16 +101,22 @@ func (d *DatabaseRepo) WithoutByFrom(from string) DBOption {
func (d *DatabaseRepo) WithTypeList(dbType string) DBOption {
return func(g *gorm.DB) *gorm.DB {
types := strings.Split(dbType, ",")
if len(types) == 1 {
if !strings.Contains(dbType, ",") {
return g.Where("`type` = ?", dbType)
}
types := strings.Split(dbType, ",")
var (
rules []string
values []interface{}
)
for _, ty := range types {
if len(ty) != 0 {
g.Or("`type` = ?", ty)
rules = append(rules, "`type` = ?")
values = append(values, ty)
}
}
return g
fmt.Println(strings.Join(rules, " OR "))
return g.Where(strings.Join(rules, " OR "), values...)
}
}

View File

@ -486,7 +486,7 @@ var EncryptHostPassword = &gormigrate.Migration{
var AddRemoteDB = &gormigrate.Migration{
ID: "20230724-add-remote-db",
Migrate: func(tx *gorm.DB) error {
if err := tx.AutoMigrate(&model.DatabaseMysql{}); err != nil {
if err := tx.AutoMigrate(&model.Database{}, &model.DatabaseMysql{}); err != nil {
return err
}
var (