Skip to content

Commit 8ea2d64

Browse files
committed
correct documentation
1 parent 377dc36 commit 8ea2d64

File tree

2 files changed

+38
-52
lines changed

2 files changed

+38
-52
lines changed

Firestore/Swift/Source/SwiftAPI/Pipeline/Expression.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ public protocol Expression: Sendable {
10221022
///
10231023
/// ```swift
10241024
/// // Calculate the average age of users
1025-
/// Field("age").average().alias("averageAge")
1025+
/// Field("age").average().as("averageAge")
10261026
/// ```
10271027
///
10281028
/// - Returns: A new `AggregateFunction` representing the "average" aggregation.
@@ -1600,7 +1600,7 @@ public protocol Expression: Sendable {
16001600
/// Field("a").divide(Field("b")).ifError(Field("fallbackValue"))
16011601
/// ```
16021602
///
1603-
/// - Parameter catchExpr: The `Expr` to evaluate and return if this expression errors.
1603+
/// - Parameter catchExpr: The `Expression` to evaluate and return if this expression errors.
16041604
/// - Returns: A new "FunctionExpression" representing the "ifError" operation.
16051605
func ifError(_ catchExpr: Expression) -> FunctionExpression
16061606

Firestore/Swift/Source/SwiftAPI/Pipeline/Pipeline.swift

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -125,25 +125,18 @@ public struct Pipeline: @unchecked Sendable {
125125
/// stages or constants. You can use this to create new fields or overwrite existing ones
126126
/// (if there is a name overlap).
127127
///
128-
/// The added fields are defined using `Selectable`s, which can be:
129-
/// - `Field`: References an existing document field.
130-
/// - `Function`: Performs a calculation using functions like `Function.add` or
131-
/// `Function.multiply`,
132-
/// typically with an assigned alias (e.g., `Function.multiply(Field("price"),
133-
/// 1.1).as("priceWithTax")`).
134-
///
135128
/// ```swift
136129
/// // let pipeline: Pipeline = ... // Assume initial pipeline from a collection.
137-
/// let updatedPipeline = pipeline.addFields(
130+
/// let updatedPipeline = pipeline.addFields([
138131
/// Field("rating").as("bookRating"), // Rename 'rating' to 'bookRating'.
139-
/// Function.add(5, Field("quantity")).as("totalQuantityPlusFive") // Calculate
140-
/// 'totalQuantityPlusFive'.
141-
/// )
132+
/// Field("quantity").add(5).as("totalQuantityPlusFive") // Calculate
133+
/// // 'totalQuantityPlusFive'.
134+
/// ])
142135
/// // let results = try await updatedPipeline.execute()
143136
/// ```
144137
///
145-
/// - Parameter field: The first field to add to the documents, specified as a `Selectable`.
146-
/// - Parameter additionalFields: Optional additional fields to add, specified as `Selectable`s.
138+
/// - Parameter fields: The fields to add to the documents, specified as an array of
139+
/// `AliasedExpression`.
147140
/// - Returns: A new `Pipeline` object with this stage appended.
148141
public func addFields(_ fields: [AliasedExpression]) -> Pipeline {
149142
return Pipeline(stages: stages + [AddFields(fields: fields)], db: db)
@@ -153,12 +146,12 @@ public struct Pipeline: @unchecked Sendable {
153146
///
154147
/// ```swift
155148
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
156-
/// let updatedPipeline = pipeline.removeFields(Field("confidentialData"), Field("internalNotes"))
149+
/// let updatedPipeline = pipeline.removeFields([Field("confidentialData"),
150+
/// Field("internalNotes")])
157151
/// // let results = try await updatedPipeline.execute()
158152
/// ```
159153
///
160-
/// - Parameter field: The first field to remove, specified as a `Field` instance.
161-
/// - Parameter additionalFields: Optional additional fields to remove.
154+
/// - Parameter fields: An array of `Field` instances to remove.
162155
/// - Returns: A new `Pipeline` object with this stage appended.
163156
public func removeFields(_ fields: [Field]) -> Pipeline {
164157
return Pipeline(
@@ -172,12 +165,11 @@ public struct Pipeline: @unchecked Sendable {
172165
/// ```swift
173166
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
174167
/// // Removes fields 'rating' and 'cost' from the previous stage outputs.
175-
/// let updatedPipeline = pipeline.removeFields("rating", "cost")
168+
/// let updatedPipeline = pipeline.removeFields(["rating", "cost"])
176169
/// // let results = try await updatedPipeline.execute()
177170
/// ```
178171
///
179-
/// - Parameter field: The name of the first field to remove.
180-
/// - Parameter additionalFields: Optional additional field names to remove.
172+
/// - Parameter fields: An array of field names to remove.
181173
/// - Returns: A new `Pipeline` object with this stage appended.
182174
public func removeFields(_ fields: [String]) -> Pipeline {
183175
return Pipeline(
@@ -191,27 +183,25 @@ public struct Pipeline: @unchecked Sendable {
191183
/// The selected fields are defined using `Selectable` expressions, which can be:
192184
/// - `String`: Name of an existing field (implicitly converted to `Field`).
193185
/// - `Field`: References an existing field.
194-
/// - `Function`: Represents the result of a function with an assigned alias
195-
/// (e.g., `Function.toUppercase(Field("address")).as("upperAddress")`).
186+
/// - `FunctionExpression`: Represents the result of a function with an assigned alias
187+
/// (e.g., `Field("address").uppercased().as("upperAddress")`).
196188
///
197189
/// If no selections are provided, the output of this stage is typically empty.
198190
/// Use `addFields` if only additions are desired without replacing the existing document
199191
/// structure.
200192
///
201193
/// ```swift
202194
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
203-
/// let projectedPipeline = pipeline.select(
195+
/// let projectedPipeline = pipeline.select([
204196
/// Field("firstName"),
205197
/// Field("lastName"),
206-
/// Function.toUppercase(Field("address")).as("upperAddress")
207-
/// )
198+
/// Field("address").uppercased().as("upperAddress")
199+
/// ])
208200
/// // let results = try await projectedPipeline.execute()
209201
/// ```
210202
///
211-
/// - Parameter selection: The first field to include in the output documents, specified as a
212-
/// `Selectable`.
213-
/// - Parameter additionalSelections: Optional additional fields to include, specified as
214-
/// `Selectable`s.
203+
/// - Parameter selections: An array of `Selectable` expressions to include in the output
204+
/// documents.
215205
/// - Returns: A new `Pipeline` object with this stage appended.
216206
public func select(_ selections: [Selectable]) -> Pipeline {
217207
return Pipeline(
@@ -227,12 +217,11 @@ public struct Pipeline: @unchecked Sendable {
227217
///
228218
/// ```swift
229219
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
230-
/// let projectedPipeline = pipeline.select("title", "author", "yearPublished")
220+
/// let projectedPipeline = pipeline.select(["title", "author", "yearPublished"])
231221
/// // let results = try await projectedPipeline.execute()
232222
/// ```
233223
///
234-
/// - Parameter selection: The name of the first field to include in the output documents.
235-
/// - Parameter additionalSelections: Optional additional field names to include.
224+
/// - Parameter selections: An array of field names to include in the output documents.
236225
/// - Returns: A new `Pipeline` object with this stage appended.
237226
public func select(_ selections: [String]) -> Pipeline {
238227
let selections = selections.map { Field($0) }
@@ -243,25 +232,24 @@ public struct Pipeline: @unchecked Sendable {
243232
}
244233

245234
/// Filters documents from previous stages, including only those matching the specified
246-
/// `BooleanExpr`.
235+
/// `BooleanExpression`.
247236
///
248237
/// This stage applies conditions similar to a "WHERE" clause in SQL.
249-
/// Filter documents based on field values using `BooleanExpr` implementations, such as:
250-
/// - Field comparators: `Function.equal`, `Function.lessThan` (less than), `Function.gt` (greater
251-
/// than).
252-
/// - Logical operators: `Function.and`, `Function.or`, `Function.not`.
253-
/// - Advanced functions: `Function.regexMatch`, `Function.arrayContains`.
238+
/// Filter documents based on field values using `BooleanExpression` implementations, such as:
239+
/// - Field comparators: `equal`, `lessThan`, `greaterThan`.
240+
/// - Logical operators: `&&` (and), `||` (or), `!` (not).
241+
/// - Advanced functions: `regexMatch`, `arrayContains`.
254242
///
255243
/// ```swift
256244
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
257245
/// let filteredPipeline = pipeline.where(
258-
/// Field("rating").gt(4.0) // Rating greater than 4.0.
246+
/// Field("rating").greaterThan(4.0) // Rating greater than 4.0.
259247
/// && Field("genre").equal("Science Fiction") // Genre is "Science Fiction".
260248
/// )
261249
/// // let results = try await filteredPipeline.execute()
262250
/// ```
263251
///
264-
/// - Parameter condition: The `BooleanExpr` to apply.
252+
/// - Parameter condition: The `BooleanExpression` to apply.
265253
/// - Returns: A new `Pipeline` object with this stage appended.
266254
public func `where`(_ condition: BooleanExpression) -> Pipeline {
267255
return Pipeline(stages: stages + [Where(condition: condition)], db: db)
@@ -451,16 +439,14 @@ public struct Pipeline: @unchecked Sendable {
451439
/// ```swift
452440
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
453441
/// // Sort books by rating (descending), then by title (ascending).
454-
/// let sortedPipeline = pipeline.sort(
455-
/// Ascending("rating"),
456-
/// Descending("title") // or Field("title").ascending() for ascending.
457-
/// )
442+
/// let sortedPipeline = pipeline.sort([
443+
/// Field("rating").descending(),
444+
/// Field("title").ascending()
445+
/// ])
458446
/// // let results = try await sortedPipeline.execute()
459447
/// ```
460448
///
461-
/// - Parameter ordering: The primary `Ordering` criterion.
462-
/// - Parameter additionalOrdering: Optional additional `Ordering` criteria for secondary sorting,
463-
/// etc.
449+
/// - Parameter orderings: An array of `Ordering` criteria.
464450
/// - Returns: A new `Pipeline` object with this stage appended.
465451
public func sort(_ orderings: [Ordering]) -> Pipeline {
466452
return Pipeline(stages: stages + [Sort(orderings: orderings)], db: db)
@@ -561,12 +547,12 @@ public struct Pipeline: @unchecked Sendable {
561547
///
562548
/// ```swift
563549
/// // let db: Firestore = ...
564-
/// // let booksPipeline = db.collection("books").pipeline().select("title", "category")
565-
/// // let magazinesPipeline = db.collection("magazines").pipeline().select("title",
566-
/// Field("topic").as("category"))
550+
/// // let booksPipeline = db.pipeline().collection("books").select(["title", "category"])
551+
/// // let magazinesPipeline = db.pipeline().collection("magazines").select(["title",
552+
/// // Field("topic").as("category")])
567553
///
568554
/// // Emit documents from both "books" and "magazines" collections.
569-
/// let combinedPipeline = booksPipeline.union(magazinesPipeline)
555+
/// let combinedPipeline = booksPipeline.union(with: [magazinesPipeline])
570556
/// // let results = try await combinedPipeline.execute()
571557
/// ```
572558
///

0 commit comments

Comments
 (0)