Skip to content

Commit becacc7

Browse files
authored
Merge pull request #1 from ypopovych/master
Strings to enum constants
2 parents c96a5da + c5be72b commit becacc7

File tree

3 files changed

+294
-216
lines changed

3 files changed

+294
-216
lines changed

Sources/SQLite/Typed/AggregateFunctions.swift

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,19 @@
2222
// THE SOFTWARE.
2323
//
2424

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+
2538
extension ExpressionType where UnderlyingType : Value {
2639

2740
/// Builds a copy of the expression prefixed with the `DISTINCT` keyword.
@@ -48,7 +61,7 @@ extension ExpressionType where UnderlyingType : Value {
4861
/// - Returns: A copy of the expression wrapped with the `count` aggregate
4962
/// function.
5063
public var count: Expression<Int> {
51-
return "count".wrap(self)
64+
return Functions.count.wrap(self)
5265
}
5366

5467
}
@@ -79,7 +92,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
7992
/// - Returns: A copy of the expression wrapped with the `count` aggregate
8093
/// function.
8194
public var count: Expression<Int> {
82-
return "count".wrap(self)
95+
return Functions.count.wrap(self)
8396
}
8497

8598
}
@@ -96,7 +109,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
96109
/// - Returns: A copy of the expression wrapped with the `max` aggregate
97110
/// function.
98111
public var max: Expression<UnderlyingType?> {
99-
return "max".wrap(self)
112+
return Functions.max.wrap(self)
100113
}
101114

102115
/// Builds a copy of the expression wrapped with the `min` aggregate
@@ -109,7 +122,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
109122
/// - Returns: A copy of the expression wrapped with the `min` aggregate
110123
/// function.
111124
public var min: Expression<UnderlyingType?> {
112-
return "min".wrap(self)
125+
return Functions.min.wrap(self)
113126
}
114127

115128
}
@@ -126,7 +139,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
126139
/// - Returns: A copy of the expression wrapped with the `max` aggregate
127140
/// function.
128141
public var max: Expression<UnderlyingType> {
129-
return "max".wrap(self)
142+
return Functions.max.wrap(self)
130143
}
131144

132145
/// Builds a copy of the expression wrapped with the `min` aggregate
@@ -139,7 +152,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
139152
/// - Returns: A copy of the expression wrapped with the `min` aggregate
140153
/// function.
141154
public var min: Expression<UnderlyingType> {
142-
return "min".wrap(self)
155+
return Functions.min.wrap(self)
143156
}
144157

145158
}
@@ -156,7 +169,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
156169
/// - Returns: A copy of the expression wrapped with the `min` aggregate
157170
/// function.
158171
public var average: Expression<Double?> {
159-
return "avg".wrap(self)
172+
return Functions.avg.wrap(self)
160173
}
161174

162175
/// Builds a copy of the expression wrapped with the `sum` aggregate
@@ -169,7 +182,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
169182
/// - Returns: A copy of the expression wrapped with the `min` aggregate
170183
/// function.
171184
public var sum: Expression<UnderlyingType?> {
172-
return "sum".wrap(self)
185+
return Functions.sum.wrap(self)
173186
}
174187

175188
/// Builds a copy of the expression wrapped with the `total` aggregate
@@ -182,7 +195,7 @@ extension ExpressionType where UnderlyingType : Value, UnderlyingType.Datatype :
182195
/// - Returns: A copy of the expression wrapped with the `min` aggregate
183196
/// function.
184197
public var total: Expression<Double> {
185-
return "total".wrap(self)
198+
return Functions.total.wrap(self)
186199
}
187200

188201
}
@@ -199,7 +212,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
199212
/// - Returns: A copy of the expression wrapped with the `min` aggregate
200213
/// function.
201214
public var average: Expression<Double?> {
202-
return "avg".wrap(self)
215+
return Functions.avg.wrap(self)
203216
}
204217

205218
/// Builds a copy of the expression wrapped with the `sum` aggregate
@@ -212,7 +225,7 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
212225
/// - Returns: A copy of the expression wrapped with the `min` aggregate
213226
/// function.
214227
public var sum: Expression<UnderlyingType> {
215-
return "sum".wrap(self)
228+
return Functions.sum.wrap(self)
216229
}
217230

218231
/// Builds a copy of the expression wrapped with the `total` aggregate
@@ -225,15 +238,15 @@ extension ExpressionType where UnderlyingType : _OptionalType, UnderlyingType.Wr
225238
/// - Returns: A copy of the expression wrapped with the `min` aggregate
226239
/// function.
227240
public var total: Expression<Double> {
228-
return "total".wrap(self)
241+
return Functions.total.wrap(self)
229242
}
230243

231244
}
232245

233246
extension ExpressionType where UnderlyingType == Int {
234247

235248
static func count(_ star: Star) -> Expression<UnderlyingType> {
236-
return "count".wrap(star(nil, nil))
249+
return Functions.count.wrap(star(nil, nil))
237250
}
238251

239252
}

0 commit comments

Comments
 (0)