Skip to content

Commit 4b880e6

Browse files
authored
Merge pull request vapor#99 from stjernegard/master
Allow custom binary operators
2 parents dffb708 + e3853d1 commit 4b880e6

File tree

1 file changed

+103
-187
lines changed

1 file changed

+103
-187
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,191 +1,107 @@
11
/// PostgreSQL specific `SQLBinaryOperator`.
2-
public enum PostgreSQLBinaryOperator: SQLBinaryOperator, Equatable {
3-
/// See `SQLBinaryOperator`.
4-
public static var equal: PostgreSQLBinaryOperator { return ._equal }
5-
6-
/// See `SQLBinaryOperator`.
7-
public static var notEqual: PostgreSQLBinaryOperator { return ._notEqual }
8-
9-
/// See `SQLBinaryOperator`.
10-
public static var greaterThan: PostgreSQLBinaryOperator { return ._greaterThan }
11-
12-
/// See `SQLBinaryOperator`.
13-
public static var lessThan: PostgreSQLBinaryOperator { return ._lessThan }
14-
15-
/// See `SQLBinaryOperator`.
16-
public static var greaterThanOrEqual: PostgreSQLBinaryOperator { return ._greaterThanOrEqual }
17-
18-
/// See `SQLBinaryOperator`.
19-
public static var lessThanOrEqual: PostgreSQLBinaryOperator { return ._lessThanOrEqual }
20-
21-
/// See `SQLBinaryOperator`.
22-
public static var like: PostgreSQLBinaryOperator { return ._like }
23-
24-
/// See `SQLBinaryOperator`.
25-
public static var notLike: PostgreSQLBinaryOperator { return ._notLike }
26-
27-
/// See `SQLBinaryOperator`.
28-
public static var `in`: PostgreSQLBinaryOperator { return ._in }
29-
30-
/// See `SQLBinaryOperator`.
31-
public static var `notIn`: PostgreSQLBinaryOperator { return ._notIn }
32-
33-
/// See `SQLBinaryOperator`.
34-
public static var and: PostgreSQLBinaryOperator { return ._and }
35-
36-
/// See `SQLBinaryOperator`.
37-
public static var or: PostgreSQLBinaryOperator { return ._or }
38-
39-
/// See `SQLBinaryOperator`.
40-
public static var concatenate: PostgreSQLBinaryOperator { return ._concatenate }
41-
42-
/// See `SQLBinaryOperator`.
43-
public static var multiply: PostgreSQLBinaryOperator { return ._multiply }
44-
45-
/// See `SQLBinaryOperator`.
46-
public static var divide: PostgreSQLBinaryOperator { return ._divide }
47-
48-
/// See `SQLBinaryOperator`.
49-
public static var modulo: PostgreSQLBinaryOperator { return ._modulo }
50-
51-
/// See `SQLBinaryOperator`.
52-
public static var add: PostgreSQLBinaryOperator { return ._add }
53-
54-
/// See `SQLBinaryOperator`.
55-
public static var subtract: PostgreSQLBinaryOperator { return ._subtract }
56-
57-
58-
/// `||`
59-
case _concatenate
60-
61-
/// `*`
62-
case _multiply
63-
64-
/// `/`
65-
case _divide
66-
67-
/// `%`
68-
case _modulo
69-
70-
/// `+`
71-
case _add
72-
73-
/// `-`
74-
case _subtract
75-
76-
/// `<<`
77-
case _bitwiseShiftLeft
78-
79-
/// `>>`
80-
case _bitwiseShiftRight
81-
82-
/// `&`
83-
case _bitwiseAnd
84-
85-
/// `|`
86-
case _bitwiseOr
87-
88-
/// `<`
89-
case _lessThan
90-
91-
/// `<=`
92-
case _lessThanOrEqual
93-
94-
/// `>`
95-
case _greaterThan
96-
97-
/// `>=`
98-
case _greaterThanOrEqual
99-
100-
/// `=` or `==`
101-
case _equal
102-
103-
/// `!=` or `<>`
104-
case _notEqual
105-
106-
/// `AND`
107-
case _and
108-
109-
/// `OR`
110-
case _or
111-
112-
/// `IS`
113-
case _is
114-
115-
/// `IS NOT`
116-
case _isNot
117-
118-
/// `IN`
119-
case _in
120-
121-
/// `NOT IN`
122-
case _notIn
123-
124-
/// `LIKE`
125-
case _like
126-
127-
/// `NOT LIKE`
128-
case _notLike
129-
130-
/// `GLOB`
131-
case _glob
132-
133-
/// `NOT GLOB`
134-
case _notGlob
135-
136-
/// `MATCH`
137-
case _match
138-
139-
/// `NOT MATCH`
140-
case _notMatch
141-
142-
/// `REGEXP`
143-
case _regexp
144-
145-
/// `NOT REGEXP`
146-
case _notRegexp
147-
148-
/// `ILIKE`
149-
case ilike
150-
151-
/// `NOT ILIKE`
152-
case notILike
153-
154-
/// See `SQLSerializable`.
2+
public struct PostgreSQLBinaryOperator: SQLBinaryOperator, Equatable, ExpressibleByStringLiteral {
3+
/// See `SQLBinaryOperator`.
4+
public static let add: PostgreSQLBinaryOperator = "+"
5+
6+
/// See `SQLBinaryOperator`.
7+
public static let bitwiseAnd: PostgreSQLBinaryOperator = "&"
8+
9+
/// See `SQLBinaryOperator`.
10+
public static let bitwiseOr: PostgreSQLBinaryOperator = "|"
11+
12+
/// See `SQLBinaryOperator`.
13+
public static let bitwiseShiftLeft: PostgreSQLBinaryOperator = "<<"
14+
15+
/// See `SQLBinaryOperator`.
16+
public static let bitwiseShiftRight: PostgreSQLBinaryOperator = ">>"
17+
18+
/// See `SQLBinaryOperator`.
19+
public static let concatenate: PostgreSQLBinaryOperator = "||"
20+
21+
/// See `SQLBinaryOperator`.
22+
public static let divide: PostgreSQLBinaryOperator = "/"
23+
24+
/// See `SQLBinaryOperator`.
25+
public static let equal: PostgreSQLBinaryOperator = "="
26+
27+
/// See `SQLBinaryOperator`.
28+
public static let greaterThan: PostgreSQLBinaryOperator = ">"
29+
30+
/// See `SQLBinaryOperator`.
31+
public static let greaterThanOrEqual: PostgreSQLBinaryOperator = ">="
32+
33+
/// See `SQLBinaryOperator`.
34+
public static let lessThan: PostgreSQLBinaryOperator = "<"
35+
36+
/// See `SQLBinaryOperator`.
37+
public static let lessThanOrEqual: PostgreSQLBinaryOperator = "<="
38+
39+
/// See `SQLBinaryOperator`.
40+
public static let modulo: PostgreSQLBinaryOperator = "%"
41+
42+
/// See `SQLBinaryOperator`.
43+
public static let multiply: PostgreSQLBinaryOperator = "*"
44+
45+
/// See `SQLBinaryOperator`.
46+
public static let notEqual: PostgreSQLBinaryOperator = "!="
47+
48+
/// See `SQLBinaryOperator`.
49+
public static let subtract: PostgreSQLBinaryOperator = "-"
50+
51+
/// See `SQLBinaryOperator`.
52+
public static let and: PostgreSQLBinaryOperator = "AND"
53+
54+
/// See `SQLBinaryOperator`.
55+
public static let or: PostgreSQLBinaryOperator = "OR"
56+
57+
/// See `SQLBinaryOperator`.
58+
public static let `in`: PostgreSQLBinaryOperator = "IN"
59+
60+
/// See `SQLBinaryOperator`.
61+
public static let notIn: PostgreSQLBinaryOperator = "NOT IN"
62+
63+
/// See `SQLBinaryOperator`.
64+
public static let `is`: PostgreSQLBinaryOperator = "IS"
65+
66+
/// See `SQLBinaryOperator`.
67+
public static let isNot: PostgreSQLBinaryOperator = "IS NOT"
68+
69+
/// See `SQLBinaryOperator`.
70+
public static let like: PostgreSQLBinaryOperator = "LIKE"
71+
72+
/// See `SQLBinaryOperator`.
73+
public static let glob: PostgreSQLBinaryOperator = "GLOB"
74+
75+
/// See `SQLBinaryOperator`.
76+
public static let match: PostgreSQLBinaryOperator = "MATCH"
77+
78+
/// See `SQLBinaryOperator`.
79+
public static let regexp: PostgreSQLBinaryOperator = "~"
80+
81+
/// See `SQLBinaryOperator`.
82+
public static let notLike: PostgreSQLBinaryOperator = "NOT LIKE"
83+
84+
/// See `SQLBinaryOperator`.
85+
public static let notGlob: PostgreSQLBinaryOperator = "NOT GLOB"
86+
87+
/// See `SQLBinaryOperator`.
88+
public static let notMatch: PostgreSQLBinaryOperator = "NOT MATCH"
89+
90+
/// See `SQLBinaryOperator`.
91+
public static let notRegexp: PostgreSQLBinaryOperator = "NOT REGEXP"
92+
93+
/// See `SQLBinaryOperator`.
94+
public static let ilike: PostgreSQLBinaryOperator = "ILIKE"
95+
96+
/// See `SQLBinaryOperator`.
97+
public static let notILike: PostgreSQLBinaryOperator = "NOT ILIKE"
98+
99+
private let op: String
100+
public init(stringLiteral value: String) {
101+
self.op = value
102+
}
103+
155104
public func serialize(_ binds: inout [Encodable]) -> String {
156-
switch self {
157-
case ._add: return "+"
158-
case ._bitwiseAnd: return "&"
159-
case ._bitwiseOr: return "|"
160-
case ._bitwiseShiftLeft: return "<<"
161-
case ._bitwiseShiftRight: return ">>"
162-
case ._concatenate: return "||"
163-
case ._divide: return "/"
164-
case ._equal: return "="
165-
case ._greaterThan: return ">"
166-
case ._greaterThanOrEqual: return ">="
167-
case ._lessThan: return "<"
168-
case ._lessThanOrEqual: return "<="
169-
case ._modulo: return "%"
170-
case ._multiply: return "*"
171-
case ._notEqual: return "!="
172-
case ._subtract: return "-"
173-
case ._and: return "AND"
174-
case ._or: return "OR"
175-
case ._in: return "IN"
176-
case ._notIn: return "NOT IN"
177-
case ._is: return "IS"
178-
case ._isNot: return "IS NOT"
179-
case ._like: return "LIKE"
180-
case ._glob: return "GLOB"
181-
case ._match: return "MATCH"
182-
case ._regexp: return "~"
183-
case ._notLike: return "NOT LIKE"
184-
case ._notGlob: return "NOT GLOB"
185-
case ._notMatch: return "NOT MATCH"
186-
case ._notRegexp: return "NOT REGEXP"
187-
case .ilike: return "ILIKE"
188-
case .notILike: return "NOT ILIKE"
189-
}
105+
return op
190106
}
191107
}

0 commit comments

Comments
 (0)