18
18
@_exported import FirebaseFirestoreInternal
19
19
#endif // SWIFT_PACKAGE
20
20
21
+ ///
22
+ /// A `Constant` is an `Expression` that represents a fixed, literal value within a Firestore pipeline.
23
+ ///
24
+ /// `Constant`s are used to introduce literal values into a query, which can be useful for:
25
+ /// - Comparing a field to a specific value in a `where` clause.
26
+ /// - Adding new fields with fixed values using `addFields`.
27
+ /// - Providing literal arguments to functions like `sum` or `average`.
28
+ ///
29
+ /// Example of using a `Constant` to add a new field:
30
+ /// ```swift
31
+ /// // Add a new field "source" with the value "manual" to each document
32
+ /// firestore.pipeline()
33
+ /// .collection("entries")
34
+ /// .addFields([
35
+ /// Constant("manual").as("source")
36
+ /// ])
37
+ /// ```
21
38
public struct Constant : Expression , BridgeWrapper , @unchecked Sendable {
22
39
let bridge : ExprBridge
23
40
@@ -33,55 +50,78 @@ public struct Constant: Expression, BridgeWrapper, @unchecked Sendable {
33
50
}
34
51
}
35
52
36
- // Initializer for integer
53
+ /// Creates a new `Constant` expression from an integer literal.
54
+ ///
55
+ /// - Parameter value: The integer value.
37
56
public init ( _ value: Int ) {
38
57
self . init ( value as Any )
39
58
}
40
59
41
- // Initializer for double
60
+ /// Creates a new `Constant` expression from a double-precision floating-point literal.
61
+ ///
62
+ /// - Parameter value: The double value.
42
63
public init ( _ value: Double ) {
43
64
self . init ( value as Any )
44
65
}
45
66
46
- // Initializer for strings
67
+ /// Creates a new `Constant` expression from a string literal.
68
+ ///
69
+ /// - Parameter value: The string value.
47
70
public init ( _ value: String ) {
48
71
self . init ( value as Any )
49
72
}
50
73
51
- // Initializer for boolean values
74
+ /// Creates a new `Constant` expression from a boolean literal.
75
+ ///
76
+ /// - Parameter value: The boolean value.
52
77
public init ( _ value: Bool ) {
53
78
self . init ( value as Any )
54
79
}
55
80
56
- // Initializer for Bytes
81
+ /// Creates a new `Constant` expression from a `Data` (bytes) literal.
82
+ ///
83
+ /// - Parameter value: The `Data` value.
57
84
public init ( _ value: Data ) {
58
85
self . init ( value as Any )
59
86
}
60
87
61
- // Initializer for GeoPoint values
88
+ /// Creates a new `Constant` expression from a `GeoPoint` literal.
89
+ ///
90
+ /// - Parameter value: The `GeoPoint` value.
62
91
public init ( _ value: GeoPoint ) {
63
92
self . init ( value as Any )
64
93
}
65
94
66
- // Initializer for Timestamp values
95
+ /// Creates a new `Constant` expression from a `Timestamp` literal.
96
+ ///
97
+ /// - Parameter value: The `Timestamp` value.
67
98
public init ( _ value: Timestamp ) {
68
99
self . init ( value as Any )
69
100
}
70
101
71
- // Initializer for Date values
102
+ /// Creates a new `Constant` expression from a `Date` literal.
103
+ ///
104
+ /// The `Date` will be converted to a `Timestamp` internally.
105
+ ///
106
+ /// - Parameter value: The `Date` value.
72
107
public init ( _ value: Date ) {
73
108
self . init ( value as Any )
74
109
}
75
110
76
- // Initializer for DocumentReference
111
+ /// Creates a new `Constant` expression from a `DocumentReference` literal.
112
+ ///
113
+ /// - Parameter value: The `DocumentReference` value.
77
114
public init ( _ value: DocumentReference ) {
78
115
self . init ( value as Any )
79
116
}
80
117
81
- // Initializer for vector values
118
+ /// Creates a new `Constant` expression from a `VectorValue` literal.
119
+ ///
120
+ /// - Parameter value: The `VectorValue` value.
82
121
public init ( _ value: VectorValue ) {
83
122
self . init ( value as Any )
84
123
}
85
124
125
+ /// A `Constant` representing a `nil` value.
86
126
public static let `nil` = Constant ( nil )
87
127
}
0 commit comments