blob: 0a43c673094cd4845aa1f8cdda67188bfb5db0f5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
namespace CrupestApi.Commons.Crud;
public class OrderByItem
{
public OrderByItem(string columnName, bool isAscending)
{
ColumnName = columnName;
IsAscending = isAscending;
}
public string ColumnName { get; }
public bool IsAscending { get; }
public string GenerateSql()
{
return $"{ColumnName} {(IsAscending ? "ASC" : "DESC")}";
}
}
public interface IOrderByClause : IClause
{
List<OrderByItem> Items { get; }
(string sql, ParamList parameters) GenerateSql(string? dbProviderId = null);
}
public class OrderByClause : IOrderByClause
{
public List<OrderByItem> Items { get; } = new List<OrderByItem>();
public OrderByClause(params OrderByItem[] items)
{
Items.AddRange(items);
}
public static OrderByClause Create(params OrderByItem[] items)
{
return new OrderByClause(items);
}
public List<string> GetRelatedColumns()
{
return Items.Select(x => x.ColumnName).ToList();
}
public (string sql, ParamList parameters) GenerateSql(string? dbProviderId = null)
{
return ("ORDER BY " + string.Join(", ", Items.Select(i => i.GenerateSql())), new ParamList());
}
}
|