@@ -5,7 +5,6 @@ enum QueryValue: Codable {
5
5
case int(Int)
6
6
case double(Double)
7
7
case bool(Bool)
8
- case query(Query)
9
8
10
9
init(from decoder: Decoder) throws {
11
10
let container = try decoder.singleValueContainer()
@@ -18,8 +17,6 @@ enum QueryValue: Codable {
18
17
self = .double(doubleValue)
19
18
} else if let boolValue = try? container.decode(Bool.self) {
20
19
self = .bool(boolValue)
21
- } else if let queryValue = try? container.decode(Query.self) {
22
- self = .query(queryValue)
23
20
} else {
24
21
throw DecodingError.dataCorruptedError(in: container, debugDescription: "QueryValue cannot be decoded")
25
22
}
@@ -36,8 +33,6 @@ enum QueryValue: Codable {
36
33
try container.encode(value)
37
34
case .bool(let value):
38
35
try container.encode(value)
39
- case .query(let value):
40
- try container.encode(value)
41
36
}
42
37
}
43
38
}
@@ -66,15 +61,13 @@ public struct Query : Codable, CustomStringConvertible {
66
61
case let valueArray as [QueryValue]:
67
62
return valueArray
68
63
case let stringArray as [String]:
69
- return stringArray.map { QueryValue .string($0) }
64
+ return stringArray.map { .string($0) }
70
65
case let intArray as [Int]:
71
- return intArray.map { QueryValue .int($0) }
66
+ return intArray.map { .int($0) }
72
67
case let doubleArray as [Double]:
73
- return doubleArray.map { QueryValue .double($0) }
68
+ return doubleArray.map { .double($0) }
74
69
case let boolArray as [Bool]:
75
- return boolArray.map { QueryValue.bool($0) }
76
- case let queryArray as [Query]:
77
- return queryArray.map { QueryValue.query($0) }
70
+ return boolArray.map { .bool($0) }
78
71
case let stringValue as String:
79
72
return [.string(stringValue)]
80
73
case let intValue as Int:
@@ -83,13 +76,11 @@ public struct Query : Codable, CustomStringConvertible {
83
76
return [.double(doubleValue)]
84
77
case let boolValue as Bool:
85
78
return [.bool(boolValue)]
86
- case let queryValue as Query:
87
- return [.query(queryValue)]
88
79
default:
89
80
return nil
90
81
}
91
82
}
92
-
83
+
93
84
enum CodingKeys: String, CodingKey {
94
85
case method
95
86
case attribute
@@ -121,47 +112,47 @@ public struct Query : Codable, CustomStringConvertible {
121
112
return Query(
122
113
method: "equal",
123
114
attribute: attribute,
124
- values: [ value]
115
+ values: Query.parseValue( value)
125
116
).description
126
117
}
127
118
128
119
public static func notEqual(_ attribute: String, value: Any) -> String {
129
120
return Query(
130
121
method: "notEqual",
131
122
attribute: attribute,
132
- values: [ value]
123
+ values: Query.parseValue( value)
133
124
).description
134
125
}
135
126
136
127
public static func lessThan(_ attribute: String, value: Any) -> String {
137
128
return Query(
138
129
method: "lessThan",
139
130
attribute: attribute,
140
- values: [ value]
131
+ values: Query.parseValue( value)
141
132
).description
142
133
}
143
134
144
135
public static func lessThanEqual(attribute: String, value: Any) -> String {
145
136
return Query(
146
137
method: "lessThanEqual",
147
138
attribute: attribute,
148
- values: [ value]
139
+ values: Query.parseValue( value)
149
140
).description
150
141
}
151
142
152
143
public static func greaterThan(_ attribute: String, value: Any) -> String {
153
144
return Query(
154
145
method: "greaterThan",
155
146
attribute: attribute,
156
- values: [ value]
147
+ values: Query.parseValue( value)
157
148
).description
158
149
}
159
150
160
151
public static func greaterThanEqual(_ attribute: String, value: Any) -> String {
161
152
return Query(
162
153
method: "greaterThanEqual",
163
154
attribute: attribute,
164
- values: [ value]
155
+ values: Query.parseValue( value)
165
156
).description
166
157
}
167
158
@@ -280,7 +271,7 @@ public struct Query : Codable, CustomStringConvertible {
280
271
return Query(
281
272
method: "contains",
282
273
attribute: attribute,
283
- values: value
274
+ values: Query.parseValue( value)
284
275
).description
285
276
}
286
277
@@ -313,4 +304,12 @@ public struct Query : Codable, CustomStringConvertible {
313
304
values: decodedQueries
314
305
).description
315
306
}
316
- }
307
+
308
+ private static func parseValue(_ value: Any) -> [Any] {
309
+ if let value = value as? [Any] {
310
+ return value
311
+ } else {
312
+ return [value]
313
+ }
314
+ }
315
+ }
0 commit comments