diff options
Diffstat (limited to 'dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/UpdateClause.cs')
-rw-r--r-- | dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/UpdateClause.cs | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/UpdateClause.cs b/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/UpdateClause.cs deleted file mode 100644 index de5c6c3..0000000 --- a/dropped/docker/crupest-api/CrupestApi/CrupestApi.Commons/Crud/UpdateClause.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System.Text; - -namespace CrupestApi.Commons.Crud; - -public class UpdateItem -{ - public UpdateItem(string columnName, object? value) - { - ColumnName = columnName; - Value = value; - } - - public string ColumnName { get; set; } - public object? Value { get; set; } -} - -public interface IUpdateClause : IClause -{ - List<UpdateItem> Items { get; } - (string sql, ParamList parameters) GenerateSql(); -} - -public class UpdateClause : IUpdateClause -{ - public List<UpdateItem> Items { get; } = new List<UpdateItem>(); - - public UpdateClause(IEnumerable<UpdateItem> items) - { - Items.AddRange(items); - } - - public UpdateClause(params UpdateItem[] items) - { - Items.AddRange(items); - } - - public UpdateClause Add(params UpdateItem[] items) - { - Items.AddRange(items); - return this; - } - - public UpdateClause Add(string column, object? value) - { - return Add(new UpdateItem(column, value)); - } - - public static UpdateClause Create(params UpdateItem[] items) - { - return new UpdateClause(items); - } - - public List<string> GetRelatedColumns() - { - return Items.Select(i => i.ColumnName).ToList(); - } - - public (string sql, ParamList parameters) GenerateSql() - { - var parameters = new ParamList(); - - StringBuilder result = new StringBuilder(); - - foreach (var item in Items) - { - if (result.Length > 0) - { - result.Append(", "); - } - - var parameterName = parameters.AddRandomNameParameter(item.Value, item.ColumnName); - result.Append($"{item.ColumnName} = @{parameterName}"); - } - - return (result.ToString(), parameters); - } -} |