@@ -2014,8 +2014,45 @@ abstract class Expr internal constructor() {
2014
2014
fun cond (condition : BooleanExpr , thenValue : Any , elseValue : Any ): Expr =
2015
2015
FunctionExpr (" cond" , condition, thenValue, elseValue)
2016
2016
2017
- /* * @return A new [Expr] representing the exists operation. */
2018
- @JvmStatic fun exists (expr : Expr ): BooleanExpr = BooleanExpr (" exists" , expr)
2017
+ /* *
2018
+ * Creates an expression that checks if a field exists.
2019
+ *
2020
+ * @param value An expression evaluates to the name of the field to check.
2021
+ * @return A new [Expr] representing the exists check.
2022
+ */
2023
+ @JvmStatic fun exists (value : Expr ): BooleanExpr = BooleanExpr (" exists" , value)
2024
+
2025
+ /* *
2026
+ * Creates an expression that checks if a field exists.
2027
+ *
2028
+ * @param fieldName The field name to check.
2029
+ * @return A new [Expr] representing the exists check.
2030
+ */
2031
+ @JvmStatic fun exists (fieldName : String ): BooleanExpr = BooleanExpr (" exists" , fieldName)
2032
+
2033
+ /* *
2034
+ * Creates an expression that returns the [catchExpr] argument if there is an
2035
+ * error, else return the result of the [tryExpr] argument evaluation.
2036
+ *
2037
+ * @param tryExpr The try expression.
2038
+ * @param catchExpr The catch expression that will be evaluated and
2039
+ * returned if the [tryExpr] produces an error.
2040
+ * @return A new [Expr] representing the ifError operation.
2041
+ */
2042
+ @JvmStatic
2043
+ fun ifError (tryExpr : Expr , catchExpr : Expr ): Expr = FunctionExpr (" if_error" , tryExpr, catchExpr)
2044
+
2045
+ /* *
2046
+ * Creates an expression that returns the [catchValue] argument if there is an
2047
+ * error, else return the result of the [tryExpr] argument evaluation.
2048
+ *
2049
+ * @param tryExpr The try expression.
2050
+ * @param catchValue The value that will be returned if the [tryExpr] produces an error.
2051
+ * @return A new [Expr] representing the ifError operation.
2052
+ */
2053
+ @JvmStatic
2054
+ fun ifError (tryExpr : Expr , catchValue : Any ): Expr =
2055
+ FunctionExpr (" if_error" , tryExpr, catchValue)
2019
2056
2020
2057
/* *
2021
2058
* Creates an expression that returns the document ID from a path.
@@ -2207,13 +2244,43 @@ abstract class Expr internal constructor() {
2207
2244
fun mod (other : Any ) = Companion .mod(this , other)
2208
2245
2209
2246
/* *
2247
+ * Creates an expression that checks if this expression, when evaluated, is equal to any of the
2248
+ * provided [values].
2249
+ *
2250
+ * @param values The values to check against.
2251
+ * @return A new [BooleanExpr] representing the 'IN' comparison.
2210
2252
*/
2211
2253
fun eqAny (values : List <Any >) = Companion .eqAny(this , values)
2212
2254
2213
2255
/* *
2256
+ * Creates an expression that checks if this expression, when evaluated, is equal to any of the
2257
+ * elements of [arrayExpression].
2258
+ *
2259
+ * @param arrayExpression An expression that evaluates to an array, whose elements to check for
2260
+ * equality to the input.
2261
+ * @return A new [BooleanExpr] representing the 'IN' comparison.
2262
+ */
2263
+ fun eqAny (arrayExpression : Expr ) = Companion .eqAny(this , arrayExpression)
2264
+
2265
+ /* *
2266
+ * Creates an expression that checks if this expression, when evaluated, is not equal to all the
2267
+ * provided [values].
2268
+ *
2269
+ * @param values The values to check against.
2270
+ * @return A new [BooleanExpr] representing the 'NOT IN' comparison.
2214
2271
*/
2215
2272
fun notEqAny (values : List <Any >) = Companion .notEqAny(this , values)
2216
2273
2274
+ /* *
2275
+ * Creates an expression that checks if this expression, when evaluated, is not equal to all the
2276
+ * elements of [arrayExpression].
2277
+ *
2278
+ * @param arrayExpression An expression that evaluates to an array, whose elements to check for
2279
+ * equality to the input.
2280
+ * @return A new [BooleanExpr] representing the 'NOT IN' comparison.
2281
+ */
2282
+ fun notEqAny (arrayExpression : Expr ) = Companion .notEqAny(this , arrayExpression)
2283
+
2217
2284
/* *
2218
2285
*/
2219
2286
fun isNan () = Companion .isNan(this )
@@ -2759,9 +2826,32 @@ abstract class Expr internal constructor() {
2759
2826
fun lte (value : Any ): BooleanExpr = Companion .lte(this , value)
2760
2827
2761
2828
/* *
2829
+ * Creates an expression that checks if this expression evaluates to a name of the field that
2830
+ * exists.
2831
+ *
2832
+ * @return A new [Expr] representing the exists check.
2762
2833
*/
2763
2834
fun exists (): BooleanExpr = Companion .exists(this )
2764
2835
2836
+ /* *
2837
+ * Creates an expression that returns the [catchExpr] argument if there is an
2838
+ * error, else return the result of this expression.
2839
+ *
2840
+ * @param catchExpr The catch expression that will be evaluated and
2841
+ * returned if the this expression produces an error.
2842
+ * @return A new [Expr] representing the ifError operation.
2843
+ */
2844
+ fun ifError (catchExpr : Expr ): Expr = Companion .ifError(this , catchExpr)
2845
+
2846
+ /* *
2847
+ * Creates an expression that returns the [catchValue] argument if there is an
2848
+ * error, else return the result of this expression.
2849
+ *
2850
+ * @param catchValue The value that will be returned if this expression produces an error.
2851
+ * @return A new [Expr] representing the ifError operation.
2852
+ */
2853
+ fun ifError (catchValue : Any ): Expr = Companion .ifError(this , catchValue)
2854
+
2765
2855
internal abstract fun toProto (userDataReader : UserDataReader ): Value
2766
2856
}
2767
2857
@@ -2838,17 +2928,24 @@ internal constructor(
2838
2928
private val params: Array <out Expr >,
2839
2929
private val options: InternalOptions = InternalOptions .EMPTY
2840
2930
) : Expr () {
2931
+ internal constructor (name: String , param: Expr ) : this (name, arrayOf(param))
2841
2932
internal constructor (
2842
2933
name: String ,
2843
2934
param: Expr ,
2844
2935
vararg params: Any
2845
2936
) : this (name, arrayOf(param, * toArrayOfExprOrConstant(params)))
2937
+ internal constructor (
2938
+ name: String ,
2939
+ param1: Expr ,
2940
+ param2: Expr
2941
+ ) : this (name, arrayOf(param1, param2))
2846
2942
internal constructor (
2847
2943
name: String ,
2848
2944
param1: Expr ,
2849
2945
param2: Expr ,
2850
2946
vararg params: Any
2851
2947
) : this (name, arrayOf(param1, param2, * toArrayOfExprOrConstant(params)))
2948
+ internal constructor (name: String , fieldName: String ) : this (name, arrayOf(field(fieldName)))
2852
2949
internal constructor (
2853
2950
name: String ,
2854
2951
fieldName: String ,
@@ -2866,18 +2963,27 @@ internal constructor(
2866
2963
}
2867
2964
}
2868
2965
2869
- /* * An interface that represents a filter condition. */
2966
+ /* * A class that represents a filter condition. */
2870
2967
open class BooleanExpr internal constructor(name : String , params : Array <out Expr >) :
2871
2968
FunctionExpr (name, params, InternalOptions .EMPTY ) {
2872
2969
internal constructor (
2873
2970
name: String ,
2874
- params : List < Any >
2875
- ) : this (name, toArrayOfExprOrConstant(params ))
2971
+ param : Expr
2972
+ ) : this (name, arrayOf(param ))
2876
2973
internal constructor (
2877
2974
name: String ,
2878
2975
param: Expr ,
2879
2976
vararg params: Any
2880
2977
) : this (name, arrayOf(param, * toArrayOfExprOrConstant(params)))
2978
+ internal constructor (
2979
+ name: String ,
2980
+ param1: Expr ,
2981
+ param2: Expr
2982
+ ) : this (name, arrayOf(param1, param2))
2983
+ internal constructor (
2984
+ name: String ,
2985
+ fieldName: String
2986
+ ) : this (name, arrayOf(field(fieldName)))
2881
2987
internal constructor (
2882
2988
name: String ,
2883
2989
fieldName: String ,
0 commit comments