refactor: Update models to use DatabaseV2 instead of DataSourceV2

This commit is contained in:
Marvin Zhang
2024-08-05 13:14:57 +08:00
parent e2cb99e56a
commit e57655c67e
21 changed files with 44 additions and 54 deletions

View File

@@ -28,7 +28,7 @@ func getCockroachdbSession(ctx context.Context, ds *models.DataSource) (s db.Ses
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultCockroachdbPort
}
@@ -73,7 +73,7 @@ func getCockroachdbSessionV2(ctx context.Context, ds *models2.DatabaseV2) (s db.
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultCockroachdbPort
}

View File

@@ -34,7 +34,7 @@ func getElasticsearchClient(ctx context.Context, ds *models.DataSource) (c *elas
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultElasticsearchPort
}
@@ -97,7 +97,7 @@ func getElasticsearchClientV2(ctx context.Context, ds *models2.DatabaseV2) (c *e
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultElasticsearchPort
}

View File

@@ -27,7 +27,7 @@ func getKafkaConnection(ctx context.Context, ds *models.DataSource) (c *kafka.Co
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultKafkaPort
}
@@ -54,7 +54,7 @@ func getKafkaConnectionV2(ctx context.Context, ds *models2.DatabaseV2) (c *kafka
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultKafkaPort
}

View File

@@ -66,7 +66,7 @@ func getMongoClient(ctx context.Context, ds *models.DataSource) (c *mongo2.Clien
if ds.Host == "" {
ds.Host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
ds.Port = constants.DefaultMongoPort
}
@@ -79,7 +79,6 @@ func getMongoClient(ctx context.Context, ds *models.DataSource) (c *mongo2.Clien
opts = append(opts, mongo.WithDb(ds.Database))
opts = append(opts, mongo.WithUsername(ds.Username))
opts = append(opts, mongo.WithPassword(ds.Password))
opts = append(opts, mongo.WithHosts(ds.Hosts))
// extra
if ds.Extra != nil {
@@ -105,7 +104,7 @@ func getMongoClientV2(ctx context.Context, ds *models2.DatabaseV2) (c *mongo2.Cl
if ds.Host == "" {
ds.Host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
ds.Port = constants.DefaultMongoPort
}
@@ -118,7 +117,6 @@ func getMongoClientV2(ctx context.Context, ds *models2.DatabaseV2) (c *mongo2.Cl
opts = append(opts, mongo.WithDb(ds.Database))
opts = append(opts, mongo.WithUsername(ds.Username))
opts = append(opts, mongo.WithPassword(ds.Password))
opts = append(opts, mongo.WithHosts(ds.Hosts))
// extra
if ds.Extra != nil {

View File

@@ -28,7 +28,7 @@ func getMssqlSession(ctx context.Context, ds *models.DataSource) (s db.Session,
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultMssqlPort
}
@@ -73,7 +73,7 @@ func getMssqlSessionV2(ctx context.Context, ds *models2.DatabaseV2) (s db.Sessio
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultMssqlPort
}

View File

@@ -28,7 +28,7 @@ func getMysqlSession(ctx context.Context, ds *models.DataSource) (s db.Session,
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultMysqlPort
}
@@ -73,7 +73,7 @@ func getMysqlSessionV2(ctx context.Context, ds *models2.DatabaseV2) (s db.Sessio
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultMysqlPort
}

View File

@@ -28,7 +28,7 @@ func getPostgresqlSession(ctx context.Context, ds *models.DataSource) (s db.Sess
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultPostgresqlPort
}
@@ -73,7 +73,7 @@ func getPostgresqlSessionV2(ctx context.Context, ds *models2.DatabaseV2) (s db.S
if ds.Host == "" {
host = constants.DefaultHost
}
if ds.Port == "" {
if ds.Port == 0 {
port = constants.DefaultPostgresqlPort
}