Skip to content

Commit

Permalink
Minor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Nov 3, 2024
1 parent 4b12cc1 commit 2ba9d65
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions JL.Core/Config/ConfigDBManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,20 @@ namespace JL.Core.Config;

public static class ConfigDBManager
{
private const string GetSettingValueQuery =
"""
SELECT value
FROM setting
WHERE profile_id = @profileId AND name = @name;
""";

private const string UpdateSettingQuery =
"""
UPDATE setting
SET value = @value
WHERE profile_id = @profileId AND name = @name;
""";

private static readonly string s_configsPath = Path.Join(Utils.ConfigPath, "Configs.sqlite");
public delegate bool TryParseHandler<T>(string value, out T? result);
public delegate bool TryParseHandlerWithCultureInfo<T>(string value, NumberStyles numberStyles, CultureInfo cultureInfo, out T result);
Expand Down Expand Up @@ -98,13 +112,7 @@ INSERT INTO setting (profile_id, name, value)
public static void UpdateSetting(SqliteConnection connection, string settingName, string value, int? profileId = null)
{
using SqliteCommand command = connection.CreateCommand();
command.CommandText =
"""
UPDATE setting
SET value = @value
WHERE profile_id = @profileId AND name = @name;
""";

command.CommandText = UpdateSettingQuery;
_ = command.Parameters.AddWithValue("@profileId", profileId ?? ProfileUtils.CurrentProfileId);
_ = command.Parameters.AddWithValue("@name", settingName);
_ = command.Parameters.AddWithValue("@value", value);
Expand Down Expand Up @@ -139,20 +147,12 @@ DELETE FROM setting
_ = command.ExecuteNonQuery();
}

public static string? GetSettingValue(SqliteConnection connection, string settingName, int? profileId = null)
public static string? GetSettingValue(SqliteConnection connection, string settingName)
{
using SqliteCommand command = connection.CreateCommand();

command.CommandText =
"""
SELECT value
FROM setting
WHERE profile_id = @profileId AND name = @name;
""";

_ = command.Parameters.AddWithValue("@profileId", profileId ?? ProfileUtils.CurrentProfileId);
command.CommandText = GetSettingValueQuery;
_ = command.Parameters.AddWithValue("@profileId", ProfileUtils.CurrentProfileId);
_ = command.Parameters.AddWithValue("@name", settingName);

return (string?)command.ExecuteScalar();
}

Expand Down

0 comments on commit 2ba9d65

Please sign in to comment.