Skip to content

Commit

Permalink
feat: add explain MongoDB queries (#314)
Browse files Browse the repository at this point in the history
* feat: add explain MongoDB queries

* nits
  • Loading branch information
cbaker6 committed Jan 8, 2022
1 parent e6c2db2 commit b92667f
Show file tree
Hide file tree
Showing 9 changed files with 596 additions and 86 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/3.0.0...main)
[Full Changelog](https://github.com/parse-community/Parse-Swift/compare/3.1.0...main)
* _Contributing to this repo? Add info about your change here to be included in the next release_

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

__New features__
- Add the ability to explain MongoDB queries by setting isUsingMongoDB = true for the respective explain query ([#314](https://github.com/parse-community/Parse-Swift/pull/314)), thanks to [Corey Baker](https://github.com/cbaker6).

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

Expand Down
4 changes: 4 additions & 0 deletions Sources/ParseSwift/API/Responses.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ internal struct AnyResultsResponse<U: Decodable>: Decodable {
let results: [U]
}

internal struct AnyResultsMongoResponse<U: Decodable>: Decodable {
let results: U
}

// MARK: ConfigResponse
internal struct ConfigFetchResponse<T>: Codable where T: ParseConfig {
let params: T
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 = "3.0.0"
static let version = "3.1.0"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
58 changes: 46 additions & 12 deletions Sources/ParseSwift/Types/Query+async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,23 @@ public extension Query {

/**
Query plan information for finding objects *asynchronously*.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- note: An explain query will have many different underlying types. Since Swift is a strongly
typed language, a developer should specify the type expected to be decoded which will be
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- returns: An array of ParseObjects.
- throws: An error of type `ParseError`.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func findExplain<U: Decodable>(options: API.Options = []) async throws -> [U] {
func findExplain<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) async throws -> [U] {
try await withCheckedThrowingContinuation { continuation in
self.findExplain(options: options,
self.findExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: continuation.resume)
}
}
Expand Down Expand Up @@ -80,13 +86,19 @@ public extension Query {
typed language, a developer should specify the type expected to be decoded which will be
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An array of ParseObjects.
- throws: An error of type `ParseError`.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func firstExplain<U: Decodable>(options: API.Options = []) async throws -> U {
func firstExplain<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) async throws -> U {
try await withCheckedThrowingContinuation { continuation in
self.firstExplain(options: options,
self.firstExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: continuation.resume)
}
}
Expand All @@ -110,14 +122,19 @@ public extension Query {
typed language, a developer should specify the type expected to be decoded which will be
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter explain: Used to toggle the information on the query plan.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An array of ParseObjects.
- throws: An error of type `ParseError`.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func countExplain<U: Decodable>(options: API.Options = []) async throws -> [U] {
func countExplain<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) async throws -> [U] {
try await withCheckedThrowingContinuation { continuation in
self.countExplain(options: options,
self.countExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: continuation.resume)
}
}
Expand All @@ -142,14 +159,19 @@ public extension Query {
typed language, a developer should specify the type expected to be decoded which will be
different for mongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter explain: Used to toggle the information on the query plan.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An array of ParseObjects.
- throws: An error of type `ParseError`.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func withCountExplain<U: Decodable>(options: API.Options = []) async throws -> [U] {
func withCountExplain<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) async throws -> [U] {
try await withCheckedThrowingContinuation { continuation in
self.withCountExplain(options: options,
self.withCountExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: continuation.resume)
}
}
Expand Down Expand Up @@ -179,16 +201,22 @@ public extension Query {
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter pipeline: A pipeline of stages to process query.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An array of ParseObjects.
- throws: An error of type `ParseError`.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func aggregateExplain<U: Decodable>(_ pipeline: [[String: Encodable]],
isUsingMongoDB: Bool = false,
options: API.Options = []) async throws -> [U] {
try await withCheckedThrowingContinuation { continuation in
self.aggregateExplain(pipeline,
options: options,
completion: continuation.resume)
isUsingMongoDB: isUsingMongoDB,
options: options,
completion: continuation.resume)
}
}

Expand Down Expand Up @@ -217,14 +245,20 @@ public extension Query {
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter key: A field to find distinct values.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: An array of ParseObjects.
- throws: An error of type `ParseError`.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func distinctExplain<U: Decodable>(_ key: String,
isUsingMongoDB: Bool = false,
options: API.Options = []) async throws -> [U] {
try await withCheckedThrowingContinuation { continuation in
self.distinctExplain(key,
isUsingMongoDB: isUsingMongoDB,
options: options,
completion: continuation.resume)
}
Expand Down
58 changes: 46 additions & 12 deletions Sources/ParseSwift/Types/Query+combine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,22 @@ public extension Query {

/**
Query plan information for finding objects *asynchronously* and publishes when complete.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- note: An explain query will have many different underlying types. Since Swift is a strongly
typed language, a developer should specify the type expected to be decoded which will be
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func findExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<[U], ParseError> {
func findExplainPublisher<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.findExplain(options: options,
self.findExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: promise)
}
}
Expand Down Expand Up @@ -78,12 +84,18 @@ public extension Query {
typed language, a developer should specify the type expected to be decoded which will be
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func firstExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<U, ParseError> {
func firstExplainPublisher<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) -> Future<U, ParseError> {
Future { promise in
self.firstExplain(options: options,
self.firstExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: promise)
}
}
Expand All @@ -106,13 +118,18 @@ public extension Query {
typed language, a developer should specify the type expected to be decoded which will be
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter explain: Used to toggle the information on the query plan.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func countExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<[U], ParseError> {
func countExplainPublisher<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.countExplain(options: options,
self.countExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: promise)
}
}
Expand All @@ -137,13 +154,18 @@ public extension Query {
typed language, a developer should specify the type expected to be decoded which will be
different for mongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter explain: Used to toggle the information on the query plan.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func withCountExplainPublisher<U: Decodable>(options: API.Options = []) -> Future<[U], ParseError> {
func withCountExplainPublisher<U: Decodable>(isUsingMongoDB: Bool = false,
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.withCountExplain(options: options,
self.withCountExplain(isUsingMongoDB: isUsingMongoDB,
options: options,
completion: promise)
}
}
Expand Down Expand Up @@ -172,15 +194,21 @@ public extension Query {
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter pipeline: A pipeline of stages to process query.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func aggregateExplainPublisher<U: Decodable>(_ pipeline: [[String: Encodable]],
isUsingMongoDB: Bool = false,
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.aggregateExplain(pipeline,
options: options,
completion: promise)
isUsingMongoDB: isUsingMongoDB,
options: options,
completion: promise)
}
}

Expand Down Expand Up @@ -208,13 +236,19 @@ public extension Query {
different for MongoDB and PostgreSQL. One way around this is to use a type-erased wrapper
such as the [AnyCodable](https://github.com/Flight-School/AnyCodable) package.
- parameter key: A field to find distinct values.
- parameter isUsingMongoDB: Set to **true** if your Parse Server uses MongoDB. Defaults to **false**.
- parameter options: A set of header options sent to the server. Defaults to an empty set.
- returns: A publisher that eventually produces a single value and then finishes or fails.
- warning: MongoDB's **explain** does not conform to the traditional Parse Server response, so the
`isUsingMongoDB` flag needs to be set for MongoDB users. See more
[here](https://github.com/parse-community/parse-server/pull/7440).
*/
func distinctExplainPublisher<U: Decodable>(_ key: String,
isUsingMongoDB: Bool = false,
options: API.Options = []) -> Future<[U], ParseError> {
Future { promise in
self.distinctExplain(key,
isUsingMongoDB: isUsingMongoDB,
options: options,
completion: promise)
}
Expand Down
Loading

0 comments on commit b92667f

Please sign in to comment.