-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #122 from MrSmoke/misc-cleanup
Misc cleanup
- Loading branch information
Showing
37 changed files
with
565 additions
and
625 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
namespace TeaTime.Data.MySql.Factories; | ||
|
||
using MySqlConnector; | ||
|
||
public interface IMySqlConnectionFactory | ||
{ | ||
MySqlConnection GetConnection(); | ||
} |
37 changes: 37 additions & 0 deletions
37
src/TeaTime.Data.MySql/Factories/MySqlConnectionFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
namespace TeaTime.Data.MySql.Factories; | ||
|
||
using System; | ||
using MySqlConnector; | ||
|
||
public class MySqlConnectionFactory : IMySqlConnectionFactory | ||
{ | ||
private readonly string _connectionString; | ||
|
||
public MySqlConnectionFactory(MySqlConnectionOptions options) | ||
{ | ||
ArgumentNullException.ThrowIfNull(options); | ||
|
||
_connectionString = GetConnectionString(options); | ||
} | ||
|
||
public MySqlConnection GetConnection() | ||
{ | ||
return new MySqlConnection(_connectionString); | ||
} | ||
|
||
private static string GetConnectionString(MySqlConnectionOptions options) | ||
{ | ||
return string.Concat( | ||
GetOption("host", options.Host), | ||
GetOption("port", options.Port.ToString()), | ||
GetOption("username", options.Username), | ||
GetOption("password", options.Password), | ||
GetOption("database", options.Database), | ||
"UseAffectedRows=true;", | ||
"DateTimeKind=utc;" | ||
); | ||
|
||
static string GetOption(string key, string? value) | ||
=> string.IsNullOrWhiteSpace(value) ? string.Empty : key + "=" + value + ";"; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/TeaTime.Data.MySql/Factories/MySqlConnectionOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
namespace TeaTime.Data.MySql.Factories; | ||
|
||
using Common.Options; | ||
|
||
public class MySqlConnectionOptions | ||
{ | ||
public string Host { get; set; } = "localhost"; | ||
public ushort Port { get; set; } = 3306; | ||
public string? Username { get; set; } | ||
public string? Password { get; set; } | ||
public string Database { get; set; } = "teatime"; | ||
|
||
public void Validate() | ||
{ | ||
if (string.IsNullOrWhiteSpace(Host)) | ||
throw new InvalidOptionException(nameof(Host), "MySql host has not been set"); | ||
|
||
if (string.IsNullOrWhiteSpace(Database)) | ||
throw new InvalidOptionException(nameof(Database), "MySql Database has not been set"); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.