36 lines
1.3 KiB
C#
36 lines
1.3 KiB
C#
using System;
|
|
using System.Globalization;
|
|
using Microsoft.Data.Sqlite;
|
|
|
|
namespace Jellyfin.Plugin.Herald.Storage;
|
|
|
|
/// <summary>
|
|
/// Value conversions shared by the stores.
|
|
/// </summary>
|
|
internal static class Db
|
|
{
|
|
public const string DateFormat = "yyyy-MM-dd";
|
|
|
|
public static string Id(Guid value) => value.ToString("N", CultureInfo.InvariantCulture);
|
|
|
|
public static Guid Id(string value) => Guid.ParseExact(value, "N");
|
|
|
|
public static string Time(DateTime value) => value.ToUniversalTime().ToString("O", CultureInfo.InvariantCulture);
|
|
|
|
public static DateTime Time(string value) => DateTime.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind).ToUniversalTime();
|
|
|
|
public static string Date(DateOnly value) => value.ToString(DateFormat, CultureInfo.InvariantCulture);
|
|
|
|
public static DateOnly Date(string value) => DateOnly.ParseExact(value, DateFormat, CultureInfo.InvariantCulture);
|
|
|
|
public static SqliteCommand Command(SqliteConnection connection, SqliteTransaction? transaction, string sql)
|
|
{
|
|
var command = connection.CreateCommand();
|
|
command.Transaction = transaction;
|
|
#pragma warning disable CA2100 // statements are constants, values are always bound as parameters
|
|
command.CommandText = sql;
|
|
#pragma warning restore CA2100
|
|
return command;
|
|
}
|
|
}
|