Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions firestore/swift/firestore-smoketest/PipelineSnippets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ public class PipelineSnippets {
pipelineConcepts()
}

func basicRead() async throws {
func stagesExpressionsExample() async throws {
// [START stages_expressions_example]
guard let cutoffDate = Calendar.current.date(byAdding: .month, value: -1, to: Date()) else {
return
}
let snapshot = try await db.pipeline()
.collection("productViews")
.where(Field("viewedAt").greaterThan(cutoffDate.timeIntervalSince1970))
.aggregate([Field("productId").countDistinct().as("uniqueProductViews")])
.execute()
// [END stages_expressions_example]
print(snapshot)
}

func basicRead() async {
// [START basic_read]
do {
// Initialize a Firestore Pipeline instance and specify the "users" collection as the
// input stage.
Expand All @@ -43,6 +58,7 @@ public class PipelineSnippets {
} catch {
print("Error getting documents with pipeline: \(error)")
}
// [END basic_read]
}

// https://cloud.google.com/firestore/docs/pipeline/overview#concepts
Expand Down Expand Up @@ -411,22 +427,6 @@ public class PipelineSnippets {
print(results)
}

// https://cloud.google.com/firestore/docs/pipeline/stages/transformation/union#examples
func unionStageStable() async throws {
// [START union_stage_stable]
let results = try await db.pipeline()
.collection("cities/SF/restaurants")
.where(Field("type").equal("Chinese"))
.union(with: db.pipeline()
.collection("cities/NY/restaurants")
.where(Field("type").equal("Italian")))
.where(Field("rating").greaterThanOrEqual(4.5))
.sort([Field("__name__").descending()])
.execute()
// [END union_stage_stable]
print(results)
}

// https://cloud.google.com/firestore/docs/pipeline/stages/transformation/unnest#examples
func unnestStage() async throws {
// [START unnest_stage]
Expand Down Expand Up @@ -1165,6 +1165,7 @@ public class PipelineSnippets {
])
.execute()
// [END to_lower]
print(result)
}

// https://cloud.google.com/firestore/docs/pipeline/functions/string_functions#substr
Expand Down Expand Up @@ -1201,7 +1202,7 @@ public class PipelineSnippets {
let result = try await db.pipeline()
.collection("books")
.select([
Field("name").trim().as("whitespaceTrimmedName")
Field("name").trim(" \n\t").as("whitespaceTrimmedName")
])
.execute()
// [END trim_function]
Expand Down
Loading