1818 @_exported import FirebaseFirestoreInternal
1919#endif // SWIFT_PACKAGE
2020
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+ /// ```
2138public struct Constant : Expression , BridgeWrapper , @unchecked Sendable {
2239 let bridge : ExprBridge
2340
@@ -33,55 +50,78 @@ public struct Constant: Expression, BridgeWrapper, @unchecked Sendable {
3350 }
3451 }
3552
36- // Initializer for integer
53+ /// Creates a new `Constant` expression from an integer literal.
54+ ///
55+ /// - Parameter value: The integer value.
3756 public init ( _ value: Int ) {
3857 self . init ( value as Any )
3958 }
4059
41- // Initializer for double
60+ /// Creates a new `Constant` expression from a double-precision floating-point literal.
61+ ///
62+ /// - Parameter value: The double value.
4263 public init ( _ value: Double ) {
4364 self . init ( value as Any )
4465 }
4566
46- // Initializer for strings
67+ /// Creates a new `Constant` expression from a string literal.
68+ ///
69+ /// - Parameter value: The string value.
4770 public init ( _ value: String ) {
4871 self . init ( value as Any )
4972 }
5073
51- // Initializer for boolean values
74+ /// Creates a new `Constant` expression from a boolean literal.
75+ ///
76+ /// - Parameter value: The boolean value.
5277 public init ( _ value: Bool ) {
5378 self . init ( value as Any )
5479 }
5580
56- // Initializer for Bytes
81+ /// Creates a new `Constant` expression from a `Data` (bytes) literal.
82+ ///
83+ /// - Parameter value: The `Data` value.
5784 public init ( _ value: Data ) {
5885 self . init ( value as Any )
5986 }
6087
61- // Initializer for GeoPoint values
88+ /// Creates a new `Constant` expression from a `GeoPoint` literal.
89+ ///
90+ /// - Parameter value: The `GeoPoint` value.
6291 public init ( _ value: GeoPoint ) {
6392 self . init ( value as Any )
6493 }
6594
66- // Initializer for Timestamp values
95+ /// Creates a new `Constant` expression from a `Timestamp` literal.
96+ ///
97+ /// - Parameter value: The `Timestamp` value.
6798 public init ( _ value: Timestamp ) {
6899 self . init ( value as Any )
69100 }
70101
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.
72107 public init ( _ value: Date ) {
73108 self . init ( value as Any )
74109 }
75110
76- // Initializer for DocumentReference
111+ /// Creates a new `Constant` expression from a `DocumentReference` literal.
112+ ///
113+ /// - Parameter value: The `DocumentReference` value.
77114 public init ( _ value: DocumentReference ) {
78115 self . init ( value as Any )
79116 }
80117
81- // Initializer for vector values
118+ /// Creates a new `Constant` expression from a `VectorValue` literal.
119+ ///
120+ /// - Parameter value: The `VectorValue` value.
82121 public init ( _ value: VectorValue ) {
83122 self . init ( value as Any )
84123 }
85124
125+ /// A `Constant` representing a `nil` value.
86126 public static let `nil` = Constant ( nil )
87127}
0 commit comments