22
22
// THE SOFTWARE.
23
23
//
24
24
25
+ private enum Functions : String {
26
+ case count
27
+ case max
28
+ case min
29
+ case avg
30
+ case sum
31
+ case total
32
+
33
+ func wrap< T> ( _ expression: Expressible ) -> Expression < T > {
34
+ return self . rawValue. wrap ( expression)
35
+ }
36
+ }
37
+
25
38
extension ExpressionType where UnderlyingType : Value {
26
39
27
40
/// Builds a copy of the expression prefixed with the `DISTINCT` keyword.
@@ -48,7 +61,7 @@ extension ExpressionType where UnderlyingType : Value {
48
61
/// - Returns: A copy of the expression wrapped with the `count` aggregate
49
62
/// function.
50
63
public var count : Expression < Int > {
51
- return " count " . wrap ( self )
64
+ return Functions . count. wrap ( self )
52
65
}
53
66
54
67
}
@@ -79,7 +92,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
79
92
/// - Returns: A copy of the expression wrapped with the `count` aggregate
80
93
/// function.
81
94
public var count : Expression < Int > {
82
- return " count " . wrap ( self )
95
+ return Functions . count. wrap ( self )
83
96
}
84
97
85
98
}
@@ -96,7 +109,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
96
109
/// - Returns: A copy of the expression wrapped with the `max` aggregate
97
110
/// function.
98
111
public var max : Expression < UnderlyingType ? > {
99
- return " max " . wrap ( self )
112
+ return Functions . max. wrap ( self )
100
113
}
101
114
102
115
/// Builds a copy of the expression wrapped with the `min` aggregate
@@ -109,7 +122,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
109
122
/// - Returns: A copy of the expression wrapped with the `min` aggregate
110
123
/// function.
111
124
public var min : Expression < UnderlyingType ? > {
112
- return " min " . wrap ( self )
125
+ return Functions . min. wrap ( self )
113
126
}
114
127
115
128
}
@@ -126,7 +139,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
126
139
/// - Returns: A copy of the expression wrapped with the `max` aggregate
127
140
/// function.
128
141
public var max : Expression < UnderlyingType > {
129
- return " max " . wrap ( self )
142
+ return Functions . max. wrap ( self )
130
143
}
131
144
132
145
/// Builds a copy of the expression wrapped with the `min` aggregate
@@ -139,7 +152,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
139
152
/// - Returns: A copy of the expression wrapped with the `min` aggregate
140
153
/// function.
141
154
public var min : Expression < UnderlyingType > {
142
- return " min " . wrap ( self )
155
+ return Functions . min. wrap ( self )
143
156
}
144
157
145
158
}
@@ -156,7 +169,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
156
169
/// - Returns: A copy of the expression wrapped with the `min` aggregate
157
170
/// function.
158
171
public var average : Expression < Double ? > {
159
- return " avg " . wrap ( self )
172
+ return Functions . avg. wrap ( self )
160
173
}
161
174
162
175
/// Builds a copy of the expression wrapped with the `sum` aggregate
@@ -169,7 +182,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
169
182
/// - Returns: A copy of the expression wrapped with the `min` aggregate
170
183
/// function.
171
184
public var sum : Expression < UnderlyingType ? > {
172
- return " sum " . wrap ( self )
185
+ return Functions . sum. wrap ( self )
173
186
}
174
187
175
188
/// Builds a copy of the expression wrapped with the `total` aggregate
@@ -182,7 +195,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
182
195
/// - Returns: A copy of the expression wrapped with the `min` aggregate
183
196
/// function.
184
197
public var total : Expression < Double > {
185
- return " total " . wrap ( self )
198
+ return Functions . total. wrap ( self )
186
199
}
187
200
188
201
}
@@ -199,7 +212,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
199
212
/// - Returns: A copy of the expression wrapped with the `min` aggregate
200
213
/// function.
201
214
public var average : Expression < Double ? > {
202
- return " avg " . wrap ( self )
215
+ return Functions . avg. wrap ( self )
203
216
}
204
217
205
218
/// Builds a copy of the expression wrapped with the `sum` aggregate
@@ -212,7 +225,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
212
225
/// - Returns: A copy of the expression wrapped with the `min` aggregate
213
226
/// function.
214
227
public var sum : Expression < UnderlyingType > {
215
- return " sum " . wrap ( self )
228
+ return Functions . sum. wrap ( self )
216
229
}
217
230
218
231
/// Builds a copy of the expression wrapped with the `total` aggregate
@@ -225,15 +238,15 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
225
238
/// - Returns: A copy of the expression wrapped with the `min` aggregate
226
239
/// function.
227
240
public var total : Expression < Double > {
228
- return " total " . wrap ( self )
241
+ return Functions . total. wrap ( self )
229
242
}
230
243
231
244
}
232
245
233
246
extension ExpressionType where UnderlyingType == Int {
234
247
235
248
static func count( _ star: Star ) -> Expression < UnderlyingType > {
236
- return " count " . wrap ( star ( nil , nil ) )
249
+ return Functions . count. wrap ( star ( nil , nil ) )
237
250
}
238
251
239
252
}
0 commit comments