@@ -552,7 +552,7 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
552
552
internal var order : [ Order ] ?
553
553
internal var isCount : Bool ?
554
554
internal var explain : Bool ?
555
- internal var hint : String ?
555
+ internal var hint : AnyEncodable ?
556
556
internal var `where` = QueryWhere ( )
557
557
internal var excludeKeys : [ String ] ?
558
558
internal var readPreference : String ?
@@ -650,6 +650,16 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
650
650
return mutableQuery
651
651
}
652
652
653
+ /**
654
+ Adds a hint to force index selection.
655
+ - parameter value: String or Object of index that should be used when executing query.
656
+ */
657
+ public func hint< U: Encodable > ( _ value: U ) -> Query < T > {
658
+ var mutableQuery = self
659
+ mutableQuery. hint = AnyEncodable ( value)
660
+ return mutableQuery
661
+ }
662
+
653
663
/**
654
664
Changes the read preference that the backend will use when performing the query to the database.
655
665
- parameter readPreference: The read preference for the main query.
@@ -855,16 +865,14 @@ extension Query: Queryable {
855
865
Finds objects *synchronously* based on the constructed query and sets an error if there was one.
856
866
857
867
- parameter explain: Used to toggle the information on the query plan.
858
- - parameter hint: String or Object of index that should be used when executing query.
859
868
- parameter options: A set of header options sent to the server. Defaults to an empty set.
860
869
- throws: An error of type `ParseError`.
861
870
862
871
- returns: Returns a response of `Decodable` type.
863
872
*/
864
873
public func find< U: Decodable > ( explain: Bool ,
865
- hint: String ? = nil ,
866
874
options: API . Options = [ ] ) throws -> [ U ] {
867
- try findCommand ( explain: explain, hint : hint ) . execute ( options: options)
875
+ try findCommand ( explain: explain) . execute ( options: options)
868
876
}
869
877
870
878
/**
@@ -889,18 +897,16 @@ extension Query: Queryable {
889
897
Finds objects *asynchronously* and calls the given block with the results.
890
898
891
899
- parameter explain: Used to toggle the information on the query plan.
892
- - parameter hint: String or Object of index that should be used when executing query.
893
900
- parameter options: A set of header options sent to the server. Defaults to an empty set.
894
901
- parameter callbackQueue: The queue to return to after completion. Default value of .main.
895
902
- parameter completion: The block to execute.
896
903
It should have the following argument signature: `(Result<[Decodable], ParseError>)`.
897
904
*/
898
905
public func find< U: Decodable > ( explain: Bool ,
899
- hint: String ? = nil ,
900
906
options: API . Options = [ ] ,
901
907
callbackQueue: DispatchQueue = . main,
902
908
completion: @escaping ( Result < [ U ] , ParseError > ) -> Void ) {
903
- findCommand ( explain: explain, hint : hint ) . executeAsync ( options: options) { result in
909
+ findCommand ( explain: explain) . executeAsync ( options: options) { result in
904
910
callbackQueue. async {
905
911
completion ( result)
906
912
}
@@ -910,7 +916,6 @@ extension Query: Queryable {
910
916
/**
911
917
Retrieves *asynchronously* a complete list of `ParseObject`'s that satisfy this query.
912
918
913
- - parameter hint: String or Object of index that should be used when executing query.
914
919
- parameter batchLimit: The maximum number of objects to send in each batch. If the items to be batched.
915
920
is greater than the `batchLimit`, the objects will be sent to the server in waves up to the `batchLimit`.
916
921
Defaults to 50.
@@ -921,8 +926,7 @@ extension Query: Queryable {
921
926
- warning: The items are processed in an unspecified order. The query may not have any sort
922
927
order, and may not use limit or skip.
923
928
*/
924
- public func findAll( hint: String ? = nil ,
925
- batchLimit limit: Int ? = nil ,
929
+ public func findAll( batchLimit limit: Int ? = nil ,
926
930
options: API . Options = [ ] ,
927
931
callbackQueue: DispatchQueue = . main,
928
932
completion: @escaping ( Result < [ ResultType ] , ParseError > ) -> Void ) {
@@ -948,8 +952,7 @@ extension Query: Queryable {
948
952
949
953
while !finished {
950
954
do {
951
- let currentResults : [ ResultType ] = try query. findCommand ( explain: false ,
952
- hint: hint) . execute ( options: options)
955
+ let currentResults = try query. findCommand ( ) . execute ( options: options)
953
956
results. append ( contentsOf: currentResults)
954
957
if currentResults. count >= query. limit {
955
958
guard let lastObjectId = results [ results. count - 1 ] . objectId else {
@@ -996,16 +999,14 @@ extension Query: Queryable {
996
999
997
1000
- warning: This method mutates the query. It will reset the limit to `1`.
998
1001
- parameter explain: Used to toggle the information on the query plan.
999
- - parameter hint: String or Object of index that should be used when executing query.
1000
1002
- parameter options: A set of header options sent to the server. Defaults to an empty set.
1001
1003
- throws: An error of type `ParseError`.
1002
1004
1003
1005
- returns: Returns a response of `Decodable` type.
1004
1006
*/
1005
1007
public func first< U: Decodable > ( explain: Bool ,
1006
- hint: String ? = nil ,
1007
1008
options: API . Options = [ ] ) throws -> U {
1008
- try firstCommand ( explain: explain, hint : hint ) . execute ( options: options)
1009
+ try firstCommand ( explain: explain) . execute ( options: options)
1009
1010
}
1010
1011
1011
1012
/**
@@ -1032,17 +1033,16 @@ extension Query: Queryable {
1032
1033
1033
1034
- warning: This method mutates the query. It will reset the limit to `1`.
1034
1035
- parameter explain: Used to toggle the information on the query plan.
1035
- - parameter hint: String or Object of index that should be used when executing query.
1036
1036
- parameter options: A set of header options sent to the server. Defaults to an empty set.
1037
1037
- parameter callbackQueue: The queue to return to after completion. Default value of `.main`.
1038
1038
- parameter completion: The block to execute.
1039
1039
It should have the following argument signature: `(Result<Decodable, ParseError>)`.
1040
1040
*/
1041
- public func first< U: Decodable > ( explain: Bool , hint : String ? = nil ,
1041
+ public func first< U: Decodable > ( explain: Bool ,
1042
1042
options: API . Options = [ ] ,
1043
1043
callbackQueue: DispatchQueue = . main,
1044
1044
completion: @escaping ( Result < U , ParseError > ) -> Void ) {
1045
- firstCommand ( explain: explain, hint : hint ) . executeAsync ( options: options) { result in
1045
+ firstCommand ( explain: explain) . executeAsync ( options: options) { result in
1046
1046
callbackQueue. async {
1047
1047
completion ( result)
1048
1048
}
@@ -1065,16 +1065,14 @@ extension Query: Queryable {
1065
1065
Counts objects *synchronously* based on the constructed query and sets an error if there was one.
1066
1066
1067
1067
- parameter explain: Used to toggle the information on the query plan.
1068
- - parameter hint: String or Object of index that should be used when executing query.
1069
1068
- parameter options: A set of header options sent to the server. Defaults to an empty set.
1070
1069
- throws: An error of type `ParseError`.
1071
1070
1072
1071
- returns: Returns a response of `Decodable` type.
1073
1072
*/
1074
1073
public func count< U: Decodable > ( explain: Bool ,
1075
- hint: String ? = nil ,
1076
1074
options: API . Options = [ ] ) throws -> U {
1077
- try countCommand ( explain: explain, hint : hint ) . execute ( options: options)
1075
+ try countCommand ( explain: explain) . execute ( options: options)
1078
1076
}
1079
1077
1080
1078
/**
@@ -1097,18 +1095,16 @@ extension Query: Queryable {
1097
1095
/**
1098
1096
Counts objects *asynchronously* and calls the given block with the counts.
1099
1097
- parameter explain: Used to toggle the information on the query plan.
1100
- - parameter hint: String or Object of index that should be used when executing query.
1101
1098
- parameter options: A set of header options sent to the server. Defaults to an empty set.
1102
1099
- parameter callbackQueue: The queue to return to after completion. Default value of `.main`.
1103
1100
- parameter completion: The block to execute.
1104
1101
It should have the following argument signature: `(Result<Decodable, ParseError>)`.
1105
1102
*/
1106
1103
public func count< U: Decodable > ( explain: Bool ,
1107
- hint: String ? = nil ,
1108
1104
options: API . Options = [ ] ,
1109
1105
callbackQueue: DispatchQueue = . main,
1110
1106
completion: @escaping ( Result < U , ParseError > ) -> Void ) {
1111
- countCommand ( explain: explain, hint : hint ) . executeAsync ( options: options) { result in
1107
+ countCommand ( explain: explain) . executeAsync ( options: options) { result in
1112
1108
callbackQueue. async {
1113
1109
completion ( result)
1114
1110
}
@@ -1216,22 +1212,18 @@ extension Query {
1216
1212
}
1217
1213
}
1218
1214
1219
- func findCommand< U: Decodable > ( explain: Bool ,
1220
- hint: String ? ) -> API . NonParseBodyCommand < Query < ResultType > , [ U ] > {
1215
+ func findCommand< U: Decodable > ( explain: Bool ) -> API . NonParseBodyCommand < Query < ResultType > , [ U ] > {
1221
1216
var query = self
1222
1217
query. explain = explain
1223
- query. hint = hint
1224
1218
return API . NonParseBodyCommand ( method: . POST, path: query. endpoint, body: query) {
1225
1219
try ParseCoding . jsonDecoder ( ) . decode ( AnyResultsResponse . self, from: $0) . results
1226
1220
}
1227
1221
}
1228
1222
1229
- func firstCommand< U: Decodable > ( explain: Bool ,
1230
- hint: String ? ) -> API . NonParseBodyCommand < Query < ResultType > , U > {
1223
+ func firstCommand< U: Decodable > ( explain: Bool ) -> API . NonParseBodyCommand < Query < ResultType > , U > {
1231
1224
var query = self
1232
1225
query. limit = 1
1233
1226
query. explain = explain
1234
- query. hint = hint
1235
1227
return API . NonParseBodyCommand ( method: . POST, path: query. endpoint, body: query) {
1236
1228
if let decoded: U = try ParseCoding . jsonDecoder ( ) . decode ( AnyResultsResponse . self, from: $0) . results. first {
1237
1229
return decoded
@@ -1241,13 +1233,11 @@ extension Query {
1241
1233
}
1242
1234
}
1243
1235
1244
- func countCommand< U: Decodable > ( explain: Bool ,
1245
- hint: String ? ) -> API . NonParseBodyCommand < Query < ResultType > , U > {
1236
+ func countCommand< U: Decodable > ( explain: Bool ) -> API . NonParseBodyCommand < Query < ResultType > , U > {
1246
1237
var query = self
1247
1238
query. limit = 1
1248
1239
query. isCount = true
1249
1240
query. explain = explain
1250
- query. hint = hint
1251
1241
return API . NonParseBodyCommand ( method: . POST, path: query. endpoint, body: query) {
1252
1242
if let decoded: U = try ParseCoding . jsonDecoder ( ) . decode ( AnyResultsResponse . self, from: $0) . results. first {
1253
1243
return decoded
0 commit comments