Skip to content

Commit

Permalink
updates db client setup with new config creation
Browse files Browse the repository at this point in the history
  • Loading branch information
tonytheleg committed May 20, 2024
1 parent e46d4fa commit b019126
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions frontend/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,37 @@ type DBClient struct {
type DBConfig struct {
DBName string
DBUrl string
<<<<<<< HEAD
=======
Cred *azidentity.DefaultAzureCredential
>>>>>>> eeedbd0 (updates db client setup with new config creation)
ClientOptions *azidentity.DefaultAzureCredentialOptions
}

// NewDatabaseConfig configures database configuration values for access
func NewDatabaseConfig() *DBConfig {
opt := &azidentity.DefaultAzureCredentialOptions{}
<<<<<<< HEAD
c := &DBConfig{
DBName: os.Getenv("DB_NAME"),
DBUrl: os.Getenv("DB_URL"),
ClientOptions: opt,
}
=======
cred, _ := azidentity.NewDefaultAzureCredential(opt)
c := &DBConfig{
DBName: os.Getenv("DB_NAME"),
DBUrl: os.Getenv("DB_URL"),
Cred: cred,
ClientOptions: opt,
}

>>>>>>> eeedbd0 (updates db client setup with new config creation)
return c
}

// NewDatabaseClient instanstiates a Cosmos DatabaseClient targeting Frontends async DB
<<<<<<< HEAD
func NewDatabaseClient(config *DBConfig) (*DBClient, error) {
cred, err := azidentity.NewDefaultAzureCredential(config.ClientOptions)
if err != nil {
Expand All @@ -56,6 +72,17 @@ func NewDatabaseClient(config *DBConfig) (*DBClient, error) {

d.client = client
return d, nil
=======
func NewDatabaseClient(config *DBConfig) *DBClient {
d := &DBClient{
config: config,
}

client, _ := azcosmos.NewClient(d.config.DBUrl, d.config.Cred, nil)

d.client = client
return d
>>>>>>> eeedbd0 (updates db client setup with new config creation)
}

// DBConnectionTest checks the async database is accessible on startup
Expand Down

0 comments on commit b019126

Please sign in to comment.