Skip to content

Commit d8c5c81

Browse files
committed
add documentations 2
1 parent 91b0dec commit d8c5c81

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,15 @@ import Foundation
3434
/// .where(Field("rating").isGreaterThan(4.5))
3535
/// .sort([Field("rating").descending()])
3636
/// .limit(2)
37+
///
38+
/// do {
39+
/// let snapshot = try await pipeline.execute()
40+
/// for doc in snapshot.results {
41+
/// print(doc.data())
42+
/// }
43+
/// } catch {
44+
/// print("Error executing pipeline: \(error)")
45+
/// }
3746
/// ```
3847
///
3948
/// - Returns: A `PipelineSource` that can be used to build and execute a pipeline.

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public struct Pipeline: @unchecked Sendable {
110110
/// // let pipeline: Pipeline = ... // Assume a pipeline is already configured.
111111
/// do {
112112
/// let snapshot = try await pipeline.execute()
113-
/// // Process snapshot.documents
114-
/// print("Pipeline executed successfully: \(snapshot.documents)")
113+
/// // Process snapshot.results
114+
/// print("Pipeline executed successfully: \(snapshot.results)")
115115
/// } catch {
116116
/// print("Pipeline execution failed: \(error)")
117117
/// }
@@ -301,7 +301,7 @@ public struct Pipeline: @unchecked Sendable {
301301
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
302302
/// // Limit results to the top 10 highest-rated books.
303303
/// let topTenPipeline = pipeline
304-
/// .sort(Descending(Field("rating")))
304+
/// .sort([Field("rating").descending()])
305305
/// .limit(10)
306306
/// // let results = try await topTenPipeline.execute()
307307
/// ```
@@ -320,7 +320,7 @@ public struct Pipeline: @unchecked Sendable {
320320
/// ```swift
321321
/// // let pipeline: Pipeline = ... // Assume initial pipeline.
322322
/// // Get a list of unique author and genre combinations.
323-
/// let distinctAuthorsGenresPipeline = pipeline.distinct("author", "genre")
323+
/// let distinctAuthorsGenresPipeline = pipeline.distinct(["author", "genre"])
324324
/// // To further select only the author:
325325
/// // .select("author")
326326
/// // let results = try await distinctAuthorsGenresPipeline.execute()
@@ -375,11 +375,11 @@ public struct Pipeline: @unchecked Sendable {
375375
/// // let pipeline: Pipeline = ... // Assume pipeline from "books" collection.
376376
/// // Calculate the average rating for each genre.
377377
/// let groupedAggregationPipeline = pipeline.aggregate(
378-
/// [AggregateWithas(aggregate: average(Field("rating")), alias: "avg_rating")],
378+
/// [Field("rating").average().as("avg_rating")],
379379
/// groups: [Field("genre")] // Group by the "genre" field.
380380
/// )
381381
/// // let results = try await groupedAggregationPipeline.execute()
382-
/// // results.documents might be:
382+
/// // snapshot.results might be:
383383
/// // [
384384
/// // ["genre": "SciFi", "avg_rating": 4.5],
385385
/// // ["genre": "Fantasy", "avg_rating": 4.2]
@@ -562,7 +562,7 @@ public struct Pipeline: @unchecked Sendable {
562562
/// // Field("topic").as("category")])
563563
///
564564
/// // Emit documents from both "books" and "magazines" collections.
565-
/// let combinedPipeline = booksPipeline.union(with: [magazinesPipeline])
565+
/// let combinedPipeline = booksPipeline.union(with: magazinesPipeline)
566566
/// // let results = try await combinedPipeline.execute()
567567
/// ```
568568
///

0 commit comments

Comments
 (0)