Skip to content

Commit

Permalink
feat: add variadic QueryConstraint methods (#345)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbaker6 authored Feb 25, 2022
1 parent a34c5cb commit 4d2d509
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@

### main

[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.1.0...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.2.0...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 4.2.0
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/4.1.0...4.2.0)

__New features__
- Add variadic QueryConstraint methods for or, nor, and ([#345](https://github.com/parse-community/Parse-Swift/pull/345)), thanks to [Corey Baker](https://github.com/cbaker6).

__Improvements__
- Add clientDefault static property to ParseLiveQuery which replaces the getDefault() method. getDefault() is still avaiable, but will be deprecated in ParseSwift 5.0.0 so it is recommended to switch to clientDefault ([#342](https://github.com/parse-community/Parse-Swift/pull/342)), thanks to [Corey Baker](https://github.com/cbaker6).

Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "4.1.0"
static let version = "4.2.0"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/Types/ParsePolygon.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public struct ParsePolygon: Codable, Hashable {

/**
Create new `ParsePolygon` instance with a variadic amount of coordinates.
- parameter coordinates: variadic amount of zero or more `ParseGeoPoint`'s.
- parameter coordinates: variadic amount of zero or more `ParseGeoPoint`'s.
- throws: An error of type `ParseError`.
*/
public init(_ coordinates: ParseGeoPoint...) throws {
Expand Down
35 changes: 34 additions & 1 deletion Sources/ParseSwift/Types/QueryConstraint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ public func or <T>(queries: [Query<T>]) -> QueryConstraint where T: ParseObject
return QueryConstraint(key: QueryConstraint.Comparator.or.rawValue, value: orQueries)
}

/**
Returns a `Query` that is the `or` of the passed in queries.
- parameter queries: The variadic amount of queries to `or` together.
- returns: An instance of `QueryConstraint`'s that are the `or` of the passed in queries.
*/
public func or <T>(queries: Query<T>...) -> QueryConstraint where T: ParseObject {
or(queries: queries)
}

/**
Returns a `Query` that is the `nor` of the passed in queries.
- parameter queries: The list of queries to `nor` together.
Expand All @@ -283,12 +292,21 @@ public func nor <T>(queries: [Query<T>]) -> QueryConstraint where T: ParseObject
return QueryConstraint(key: QueryConstraint.Comparator.nor.rawValue, value: orQueries)
}

/**
Returns a `Query` that is the `nor` of the passed in queries.
- parameter queries: The variadic amount of queries to `nor` together.
- returns: An instance of `QueryConstraint`'s that are the `nor` of the passed in queries.
*/
public func nor <T>(queries: Query<T>...) -> QueryConstraint where T: ParseObject {
nor(queries: queries)
}

/**
Constructs a Query that is the `and` of the passed in queries.
For example:
var compoundQueryConstraints = and(query1, query2, query3)
var compoundQueryConstraints = and([query1, query2, query3])
will create a compoundQuery that is an and of the query1, query2, and query3.
- parameter queries: The list of queries to `and` together.
Expand All @@ -299,6 +317,21 @@ public func and <T>(queries: [Query<T>]) -> QueryConstraint where T: ParseObject
return QueryConstraint(key: QueryConstraint.Comparator.and.rawValue, value: andQueries)
}

/**
Constructs a Query that is the `and` of the passed in queries.
For example:
var compoundQueryConstraints = and(query1, query2, query3)
will create a compoundQuery that is an and of the query1, query2, and query3.
- parameter queries: The variadic amount of queries to `and` together.
- returns: An instance of `QueryConstraint`'s that are the `and` of the passed in queries.
*/
public func and <T>(queries: Query<T>...) -> QueryConstraint where T: ParseObject {
and(queries: queries)
}

/**
Add a constraint that requires that a key's value matches a `Query` constraint.
- warning: This only works where the key's values are `ParseObject`s or arrays of `ParseObject`s.
Expand Down
6 changes: 3 additions & 3 deletions Tests/ParseSwiftTests/ParseQueryTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
]
let query1 = GameScore.query("points" <= 50)
let query2 = GameScore.query("points" <= 200)
let constraint = or(queries: [query1, query2])
let constraint = or(queries: query1, query2)
let query = Query<GameScore>(constraint)
let queryWhere = query.`where`

Expand Down Expand Up @@ -1772,7 +1772,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
]
let query1 = GameScore.query("points" <= 50)
let query2 = GameScore.query("points" <= 200)
let constraint = nor(queries: [query1, query2])
let constraint = nor(queries: query1, query2)
let query = Query<GameScore>(constraint)
let queryWhere = query.`where`

Expand Down Expand Up @@ -1803,7 +1803,7 @@ class ParseQueryTests: XCTestCase { // swiftlint:disable:this type_body_length
]
let query1 = GameScore.query("points" <= 50)
let query2 = GameScore.query("points" <= 200)
let constraint = and(queries: [query1, query2])
let constraint = and(queries: query1, query2)
let query = Query<GameScore>(constraint)
let queryWhere = query.`where`

Expand Down

0 comments on commit 4d2d509

Please sign in to comment.