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