Skip to content

Commit

Permalink
Merge pull request #23 from masastack/feature/connectionString
Browse files Browse the repository at this point in the history
⚡ refactor: DbModel supports multiple databases
  • Loading branch information
wzh425 authored Dec 4, 2024
2 parents 310f063 + f8c3120 commit 1f4e533
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,16 @@ public class DbModel

public string Password { get; set; }

Check warning on line 16 in src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Config/Models/DbModel.cs

View workflow job for this annotation

GitHub Actions / codecov (5, 16)

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 16 in src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Config/Models/DbModel.cs

View workflow job for this annotation

GitHub Actions / package build and push

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

Check warning on line 16 in src/BuildingBlocks/Masa.BuildingBlocks.StackSdks.Config/Models/DbModel.cs

View workflow job for this annotation

GitHub Actions / package build and push

Non-nullable property 'Password' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.

public string ToString(string datebase)
public string? DbType { get; set; }

public string ToString(string database)
{
return $"Server={Server},{Port};Database={datebase};User Id={UserId};Password={Password};";
return DbType switch
{
"SqlServer" => $"Server={Server},{Port};Database={database};User Id={UserId};Password={Password};",
"PostgreSql" => $"Host={Server};Port={Port};Username={UserId};Password={Password};Database={database};",
"MySql" => $"Server={Server};Port={Port};Database={database};Uid={UserId};Pwd={Password};",
_ => $"Server={Server},{Port};Database={database};User Id={UserId};Password={Password};"
};
}
}
}

0 comments on commit 1f4e533

Please sign in to comment.