@@ -125,25 +125,18 @@ public struct Pipeline: @unchecked Sendable {
125
125
/// stages or constants. You can use this to create new fields or overwrite existing ones
126
126
/// (if there is a name overlap).
127
127
///
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
- ///
135
128
/// ```swift
136
129
/// // let pipeline: Pipeline = ... // Assume initial pipeline from a collection.
137
- /// let updatedPipeline = pipeline.addFields(
130
+ /// let updatedPipeline = pipeline.addFields([
138
131
/// 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
+ /// ] )
142
135
/// // let results = try await updatedPipeline.execute()
143
136
/// ```
144
137
///
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` .
147
140
/// - Returns: A new `Pipeline` object with this stage appended.
148
141
public func addFields( _ fields: [ AliasedExpression ] ) -> Pipeline {
149
142
return Pipeline ( stages: stages + [ AddFields ( fields: fields) ] , db: db)
@@ -153,12 +146,12 @@ public struct Pipeline: @unchecked Sendable {
153
146
///
154
147
/// ```swift
155
148
/// // 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")])
157
151
/// // let results = try await updatedPipeline.execute()
158
152
/// ```
159
153
///
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.
162
155
/// - Returns: A new `Pipeline` object with this stage appended.
163
156
public func removeFields( _ fields: [ Field ] ) -> Pipeline {
164
157
return Pipeline (
@@ -172,12 +165,11 @@ public struct Pipeline: @unchecked Sendable {
172
165
/// ```swift
173
166
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
174
167
/// // Removes fields 'rating' and 'cost' from the previous stage outputs.
175
- /// let updatedPipeline = pipeline.removeFields("rating", "cost")
168
+ /// let updatedPipeline = pipeline.removeFields([ "rating", "cost"] )
176
169
/// // let results = try await updatedPipeline.execute()
177
170
/// ```
178
171
///
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.
181
173
/// - Returns: A new `Pipeline` object with this stage appended.
182
174
public func removeFields( _ fields: [ String ] ) -> Pipeline {
183
175
return Pipeline (
@@ -191,27 +183,25 @@ public struct Pipeline: @unchecked Sendable {
191
183
/// The selected fields are defined using `Selectable` expressions, which can be:
192
184
/// - `String`: Name of an existing field (implicitly converted to `Field`).
193
185
/// - `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")`).
196
188
///
197
189
/// If no selections are provided, the output of this stage is typically empty.
198
190
/// Use `addFields` if only additions are desired without replacing the existing document
199
191
/// structure.
200
192
///
201
193
/// ```swift
202
194
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
203
- /// let projectedPipeline = pipeline.select(
195
+ /// let projectedPipeline = pipeline.select([
204
196
/// Field("firstName"),
205
197
/// Field("lastName"),
206
- /// Function.toUppercase( Field("address")).as("upperAddress")
207
- /// )
198
+ /// Field("address").uppercased( ).as("upperAddress")
199
+ /// ] )
208
200
/// // let results = try await projectedPipeline.execute()
209
201
/// ```
210
202
///
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.
215
205
/// - Returns: A new `Pipeline` object with this stage appended.
216
206
public func select( _ selections: [ Selectable ] ) -> Pipeline {
217
207
return Pipeline (
@@ -227,12 +217,11 @@ public struct Pipeline: @unchecked Sendable {
227
217
///
228
218
/// ```swift
229
219
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
230
- /// let projectedPipeline = pipeline.select("title", "author", "yearPublished")
220
+ /// let projectedPipeline = pipeline.select([ "title", "author", "yearPublished"] )
231
221
/// // let results = try await projectedPipeline.execute()
232
222
/// ```
233
223
///
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.
236
225
/// - Returns: A new `Pipeline` object with this stage appended.
237
226
public func select( _ selections: [ String ] ) -> Pipeline {
238
227
let selections = selections. map { Field ( $0) }
@@ -243,25 +232,24 @@ public struct Pipeline: @unchecked Sendable {
243
232
}
244
233
245
234
/// Filters documents from previous stages, including only those matching the specified
246
- /// `BooleanExpr `.
235
+ /// `BooleanExpression `.
247
236
///
248
237
/// 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`.
254
242
///
255
243
/// ```swift
256
244
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
257
245
/// 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.
259
247
/// && Field("genre").equal("Science Fiction") // Genre is "Science Fiction".
260
248
/// )
261
249
/// // let results = try await filteredPipeline.execute()
262
250
/// ```
263
251
///
264
- /// - Parameter condition: The `BooleanExpr ` to apply.
252
+ /// - Parameter condition: The `BooleanExpression ` to apply.
265
253
/// - Returns: A new `Pipeline` object with this stage appended.
266
254
public func `where`( _ condition: BooleanExpression ) -> Pipeline {
267
255
return Pipeline ( stages: stages + [ Where ( condition: condition) ] , db: db)
@@ -451,16 +439,14 @@ public struct Pipeline: @unchecked Sendable {
451
439
/// ```swift
452
440
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
453
441
/// // 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
+ /// ] )
458
446
/// // let results = try await sortedPipeline.execute()
459
447
/// ```
460
448
///
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.
464
450
/// - Returns: A new `Pipeline` object with this stage appended.
465
451
public func sort( _ orderings: [ Ordering ] ) -> Pipeline {
466
452
return Pipeline ( stages: stages + [ Sort ( orderings: orderings) ] , db: db)
@@ -561,12 +547,12 @@ public struct Pipeline: @unchecked Sendable {
561
547
///
562
548
/// ```swift
563
549
/// // 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")] )
567
553
///
568
554
/// // Emit documents from both "books" and "magazines" collections.
569
- /// let combinedPipeline = booksPipeline.union(magazinesPipeline)
555
+ /// let combinedPipeline = booksPipeline.union(with: [ magazinesPipeline] )
570
556
/// // let results = try await combinedPipeline.execute()
571
557
/// ```
572
558
///
0 commit comments