diff --git a/server/db/db.go b/server/db/db.go index 80b3309f1..f8255023f 100644 --- a/server/db/db.go +++ b/server/db/db.go @@ -22,64 +22,35 @@ func InitDB() error { envs := memorystore.RequiredEnvStoreObj.GetRequiredEnv() - isSQL := envs.DatabaseType != constants.DbTypeArangodb && envs.DatabaseType != constants.DbTypeMongodb && envs.DatabaseType != constants.DbTypeCassandraDB && envs.DatabaseType != constants.DbTypeScyllaDB && envs.DatabaseType != constants.DbTypeDynamoDB && envs.DatabaseType != constants.DbTypeCouchbaseDB - isArangoDB := envs.DatabaseType == constants.DbTypeArangodb - isMongoDB := envs.DatabaseType == constants.DbTypeMongodb - isCassandra := envs.DatabaseType == constants.DbTypeCassandraDB || envs.DatabaseType == constants.DbTypeScyllaDB - isDynamoDB := envs.DatabaseType == constants.DbTypeDynamoDB - isCouchbaseDB := envs.DatabaseType == constants.DbTypeCouchbaseDB - - if isSQL { - log.Info("Initializing SQL Driver for: ", envs.DatabaseType) - Provider, err = sql.NewProvider() - if err != nil { - log.Fatal("Failed to initialize SQL driver: ", err) - return err - } - } - if isArangoDB { + switch envs.DatabaseType { + case constants.DbTypeArangodb: log.Info("Initializing ArangoDB Driver") Provider, err = arangodb.NewProvider() - if err != nil { - log.Fatal("Failed to initialize ArangoDB driver: ", err) - return err - } - } - if isMongoDB { + case constants.DbTypeMongodb: log.Info("Initializing MongoDB Driver") Provider, err = mongodb.NewProvider() - if err != nil { - log.Fatal("Failed to initialize MongoDB driver: ", err) - return err - } - } - if isCassandra { + case constants.DbTypeCassandraDB, constants.DbTypeScyllaDB: log.Info("Initializing CassandraDB Driver") Provider, err = cassandradb.NewProvider() - if err != nil { - log.Fatal("Failed to initialize CassandraDB driver: ", err) - return err - } - } - if isDynamoDB { + case constants.DbTypeDynamoDB: log.Info("Initializing DynamoDB Driver for: ", envs.DatabaseType) Provider, err = dynamodb.NewProvider() - if err != nil { - log.Fatal("Failed to initialize DynamoDB driver: ", err) - return err - } - } - if isCouchbaseDB { + case constants.DbTypeCouchbaseDB: log.Info("Initializing CouchbaseDB Driver for: ", envs.DatabaseType) Provider, err = couchbase.NewProvider() - if err != nil { - log.Fatal("Failed to initialize Couchbase driver: ", err) - return err - } + + default: + log.Info("Initializing SQL Driver for: ", envs.DatabaseType) + Provider, err = sql.NewProvider() + } + + if err != nil { + log.Fatal("Failed to initialize database driver: ", err) + return err } return nil