Skip to content

Commit fd8ed65

Browse files
committed
equivalent()
1 parent d02c044 commit fd8ed65

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

Firestore/Swift/Source/ExpressionImplementation.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,4 +888,10 @@ public extension Expression {
888888
func descending() -> Ordering {
889889
return Ordering(expression: self, direction: .descending)
890890
}
891+
892+
// MARK: Equivalence Operations
893+
894+
func equivalent(_ other: Sendable) -> BooleanExpression {
895+
return BooleanExpression("equivalent", [self, Helper.sendableToExpr(other)])
896+
}
891897
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1555,4 +1555,14 @@ public protocol Expression: Sendable {
15551555
///
15561556
/// - Returns: A new `Ordering` instance for descending sorting.
15571557
func descending() -> Ordering
1558+
1559+
// MARK: Equivalence Operations
1560+
1561+
1562+
/// Creates a `BooleanExpr` that returns `true` if this expression is equivalent
1563+
/// to the given value.
1564+
///
1565+
/// - Parameter other: The value to compare against.
1566+
/// - Returns: A `BooleanExpr` that can be used in `where` clauses.
1567+
func equivalent(_ other: Sendable) -> BooleanExpression
15581568
}

Firestore/Swift/Tests/Integration/PipelineTests.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,25 @@ class PipelineIntegrationTests: FSTIntegrationTestCase {
16771677
TestHelper.compare(snapshot: snapshot, expected: expectedResults, enforceOrder: true)
16781678
}
16791679

1680+
func testEquivalentWorks() async throws {
1681+
let collRef = collectionRef(withDocuments: [
1682+
"doc1": ["value": 1, "value2": 1],
1683+
"doc2": ["value": 1, "value2": 2],
1684+
"doc3": ["value": NSNull(), "value2": NSNull()],
1685+
"doc4": ["value": NSNull(), "value2": 1],
1686+
"doc5": ["value": Double.nan, "value2": Double.nan],
1687+
"doc6": ["value": Double.nan, "value2": 1],
1688+
])
1689+
let db = collRef.firestore
1690+
1691+
let pipeline = db.pipeline()
1692+
.collection(collRef.path)
1693+
.where(Field("value").equivalent(Field("value2")))
1694+
let snapshot = try await pipeline.execute()
1695+
1696+
XCTAssertEqual(snapshot.results.count, 3)
1697+
}
1698+
16801699
func testInWorks() async throws {
16811700
let collRef = collectionRef(withDocuments: bookDocs)
16821701
let db = collRef.firestore

0 commit comments

Comments
 (0)