-
-
Notifications
You must be signed in to change notification settings - Fork 512
/
Copy pathQuery.Aggregate.cs
59 lines (48 loc) · 1.34 KB
/
Query.Aggregate.cs
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
50
51
52
53
54
55
56
57
58
59
using System.Collections.Generic;
using System.Linq;
namespace SqlKata
{
public partial class Query
{
public Query AsAggregate(string type, string[] columns = null)
{
Method = "aggregate";
this.ClearComponent("aggregate")
.AddComponent("aggregate", new AggregateClause
{
Type = type,
Columns = columns?.ToList() ?? new List<string>(),
});
return this;
}
public Query AsCount(string[] columns = null)
{
var cols = columns?.ToList() ?? new List<string> { };
if (!cols.Any())
{
cols.Add("*");
}
return AsAggregate("count", cols.ToArray());
}
public Query AsAvg(string column)
{
return AsAggregate("avg", new string[] { column });
}
public Query AsAverage(string column)
{
return AsAvg(column);
}
public Query AsSum(string column)
{
return AsAggregate("sum", new[] { column });
}
public Query AsMax(string column)
{
return AsAggregate("max", new[] { column });
}
public Query AsMin(string column)
{
return AsAggregate("min", new[] { column });
}
}
}