支持tdengine

This commit is contained in:
XM-GO
2023-06-19 17:06:38 +08:00
parent 997e0862fa
commit 8b5a0206b9
12 changed files with 186 additions and 99 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/XM-GO/PandaKit/cache"
"pandax/apps/visual/entity"
"pandax/pkg/global"
"pandax/pkg/tool"
"reflect"
"strconv"
"strings"
@@ -74,6 +75,12 @@ func (di *DbInstance) GetMeta() DbMetadata {
if dbType == entity.DbTypePostgres {
return &PgsqlMetadata{di: di}
}
if dbType == entity.DbTypeTdengine {
return &TDMetadata{di: di}
}
if dbType == entity.DbTypeClickHouse {
return &ClickHouseMetadata{di: di}
}
return nil
}
@@ -121,11 +128,10 @@ func AddDbInstanceToCache(id string, di *DbInstance) {
func TestConnection(d *entity.VisualDataSource) error {
// 验证第一个库是否可以连接即可
DB, err := GetDbConn(d)
_, err := GetDbConn(d)
if err != nil {
return err
} else {
DB.Close()
return nil
}
}
@@ -138,8 +144,11 @@ func GetDbConn(d *entity.VisualDataSource) (*sql.DB, error) {
DB, err = getMysqlDB(d)
} else if d.SourceType == entity.DbTypePostgres {
DB, err = getPgsqlDB(d)
} else if d.SourceType == entity.DbTypeTdengine {
DB, err = getTdDB(d)
} else if d.SourceType == entity.DbTypeClickHouse {
DB, err = getClickHouseDB(d)
}
if err != nil {
return nil, err
}
@@ -148,7 +157,6 @@ func GetDbConn(d *entity.VisualDataSource) (*sql.DB, error) {
DB.Close()
return nil, err
}
return DB, nil
}
@@ -195,6 +203,9 @@ func SelectDataByDb(db *sql.DB, selectSql string) ([]string, []map[string]interf
if isFirst {
colNames = append(colNames, colName)
}
if strings.Contains(colName, "_") {
colName = tool.ToCamelCase(colName)
}
rowData[colName] = valueConvert(v, colType)
}
// 放入结果集