@@ -552,7 +552,7 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
552552 internal var order : [ Order ] ?
553553 internal var isCount : Bool ?
554554 internal var explain : Bool ?
555- internal var hint : String ?
555+ internal var hint : AnyEncodable ?
556556 internal var `where` = QueryWhere ( )
557557 internal var excludeKeys : [ String ] ?
558558 internal var readPreference : String ?
@@ -650,6 +650,16 @@ public struct Query<T>: Encodable, Equatable where T: ParseObject {
650650 return mutableQuery
651651 }
652652
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+
653663 /**
654664 Changes the read preference that the backend will use when performing the query to the database.
655665 - parameter readPreference: The read preference for the main query.
@@ -855,16 +865,14 @@ extension Query: Queryable {
855865 Finds objects *synchronously* based on the constructed query and sets an error if there was one.
856866
857867 - 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.
859868 - parameter options: A set of header options sent to the server. Defaults to an empty set.
860869 - throws: An error of type `ParseError`.
861870
862871 - returns: Returns a response of `Decodable` type.
863872 */
864873 public func find< U: Decodable > ( explain: Bool ,
865- hint: String ? = nil ,
866874 options: API . Options = [ ] ) throws -> [ U ] {
867- try findCommand ( explain: explain, hint : hint ) . execute ( options: options)
875+ try findCommand ( explain: explain) . execute ( options: options)
868876 }
869877
870878 /**
@@ -889,18 +897,16 @@ extension Query: Queryable {
889897 Finds objects *asynchronously* and calls the given block with the results.
890898
891899 - 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.
893900 - parameter options: A set of header options sent to the server. Defaults to an empty set.
894901 - parameter callbackQueue: The queue to return to after completion. Default value of .main.
895902 - parameter completion: The block to execute.
896903 It should have the following argument signature: `(Result<[Decodable], ParseError>)`.
897904 */
898905 public func find< U: Decodable > ( explain: Bool ,
899- hint: String ? = nil ,
900906 options: API . Options = [ ] ,
901907 callbackQueue: DispatchQueue = . main,
902908 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
904910 callbackQueue. async {
905911 completion ( result)
906912 }
@@ -910,7 +916,6 @@ extension Query: Queryable {
910916 /**
911917 Retrieves *asynchronously* a complete list of `ParseObject`'s that satisfy this query.
912918
913- - parameter hint: String or Object of index that should be used when executing query.
914919 - parameter batchLimit: The maximum number of objects to send in each batch. If the items to be batched.
915920 is greater than the `batchLimit`, the objects will be sent to the server in waves up to the `batchLimit`.
916921 Defaults to 50.
@@ -921,8 +926,7 @@ extension Query: Queryable {
921926 - warning: The items are processed in an unspecified order. The query may not have any sort
922927 order, and may not use limit or skip.
923928 */
924- public func findAll( hint: String ? = nil ,
925- batchLimit limit: Int ? = nil ,
929+ public func findAll( batchLimit limit: Int ? = nil ,
926930 options: API . Options = [ ] ,
927931 callbackQueue: DispatchQueue = . main,
928932 completion: @escaping ( Result < [ ResultType ] , ParseError > ) -> Void ) {
@@ -948,8 +952,7 @@ extension Query: Queryable {
948952
949953 while !finished {
950954 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)
953956 results. append ( contentsOf: currentResults)
954957 if currentResults. count >= query. limit {
955958 guard let lastObjectId = results [ results. count - 1 ] . objectId else {
@@ -996,16 +999,14 @@ extension Query: Queryable {
996999
9971000 - warning: This method mutates the query. It will reset the limit to `1`.
9981001 - 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.
10001002 - parameter options: A set of header options sent to the server. Defaults to an empty set.
10011003 - throws: An error of type `ParseError`.
10021004
10031005 - returns: Returns a response of `Decodable` type.
10041006 */
10051007 public func first< U: Decodable > ( explain: Bool ,
1006- hint: String ? = nil ,
10071008 options: API . Options = [ ] ) throws -> U {
1008- try firstCommand ( explain: explain, hint : hint ) . execute ( options: options)
1009+ try firstCommand ( explain: explain) . execute ( options: options)
10091010 }
10101011
10111012 /**
@@ -1032,17 +1033,16 @@ extension Query: Queryable {
10321033
10331034 - warning: This method mutates the query. It will reset the limit to `1`.
10341035 - 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.
10361036 - parameter options: A set of header options sent to the server. Defaults to an empty set.
10371037 - parameter callbackQueue: The queue to return to after completion. Default value of `.main`.
10381038 - parameter completion: The block to execute.
10391039 It should have the following argument signature: `(Result<Decodable, ParseError>)`.
10401040 */
1041- public func first< U: Decodable > ( explain: Bool , hint : String ? = nil ,
1041+ public func first< U: Decodable > ( explain: Bool ,
10421042 options: API . Options = [ ] ,
10431043 callbackQueue: DispatchQueue = . main,
10441044 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
10461046 callbackQueue. async {
10471047 completion ( result)
10481048 }
@@ -1065,16 +1065,14 @@ extension Query: Queryable {
10651065 Counts objects *synchronously* based on the constructed query and sets an error if there was one.
10661066
10671067 - 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.
10691068 - parameter options: A set of header options sent to the server. Defaults to an empty set.
10701069 - throws: An error of type `ParseError`.
10711070
10721071 - returns: Returns a response of `Decodable` type.
10731072 */
10741073 public func count< U: Decodable > ( explain: Bool ,
1075- hint: String ? = nil ,
10761074 options: API . Options = [ ] ) throws -> U {
1077- try countCommand ( explain: explain, hint : hint ) . execute ( options: options)
1075+ try countCommand ( explain: explain) . execute ( options: options)
10781076 }
10791077
10801078 /**
@@ -1097,18 +1095,16 @@ extension Query: Queryable {
10971095 /**
10981096 Counts objects *asynchronously* and calls the given block with the counts.
10991097 - 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.
11011098 - parameter options: A set of header options sent to the server. Defaults to an empty set.
11021099 - parameter callbackQueue: The queue to return to after completion. Default value of `.main`.
11031100 - parameter completion: The block to execute.
11041101 It should have the following argument signature: `(Result<Decodable, ParseError>)`.
11051102 */
11061103 public func count< U: Decodable > ( explain: Bool ,
1107- hint: String ? = nil ,
11081104 options: API . Options = [ ] ,
11091105 callbackQueue: DispatchQueue = . main,
11101106 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
11121108 callbackQueue. async {
11131109 completion ( result)
11141110 }
@@ -1216,22 +1212,18 @@ extension Query {
12161212 }
12171213 }
12181214
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 ] > {
12211216 var query = self
12221217 query. explain = explain
1223- query. hint = hint
12241218 return API . NonParseBodyCommand ( method: . POST, path: query. endpoint, body: query) {
12251219 try ParseCoding . jsonDecoder ( ) . decode ( AnyResultsResponse . self, from: $0) . results
12261220 }
12271221 }
12281222
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 > {
12311224 var query = self
12321225 query. limit = 1
12331226 query. explain = explain
1234- query. hint = hint
12351227 return API . NonParseBodyCommand ( method: . POST, path: query. endpoint, body: query) {
12361228 if let decoded: U = try ParseCoding . jsonDecoder ( ) . decode ( AnyResultsResponse . self, from: $0) . results. first {
12371229 return decoded
@@ -1241,13 +1233,11 @@ extension Query {
12411233 }
12421234 }
12431235
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 > {
12461237 var query = self
12471238 query. limit = 1
12481239 query. isCount = true
12491240 query. explain = explain
1250- query. hint = hint
12511241 return API . NonParseBodyCommand ( method: . POST, path: query. endpoint, body: query) {
12521242 if let decoded: U = try ParseCoding . jsonDecoder ( ) . decode ( AnyResultsResponse . self, from: $0) . results. first {
12531243 return decoded
0 commit comments