FirebaseFirestore Framework Reference

Expression

public protocol Expression : Sendable

Undocumented

  • asBoolean()

    Default implementation

    Casts the expression to a BooleanExpression.

    Default Implementation

    Declaration

    Swift

    func asBoolean() -> BooleanExpression

    Return Value

    A BooleanExpression representing the same expression.

  • as(_:)

    Default implementation

    Assigns an alias to this expression.

    Aliases are useful for renaming fields in the output of a stage or for giving meaningful names to calculated values.

    // Calculate total price and alias it "totalPrice"
    Field("price").multiply(Field("quantity")).as("totalPrice")
    

    Default Implementation

    Declaration

    Swift

    func `as`(_ name: String) -> AliasedExpression

    Parameters

    name

    The alias to assign to this expression.

    Return Value

    A new AliasedExpression wrapping this expression with the alias.

  • round()

    Default implementation

    Creates an expression that returns the value of self rounded to the nearest integer.

    // Get the value of the "amount" field rounded to the nearest integer.
    Field("amount").round()
    

    Default Implementation

    Declaration

    Swift

    func round() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the rounded number.

  • sqrt()

    Default implementation

    Creates an expression that returns the square root of self.

    // Get the square root of the "area" field.
    Field("area").sqrt()
    

    Default Implementation

    Declaration

    Swift

    func sqrt() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the square root of the number.

  • pow(_:)

    Default implementation

    Creates an expression that returns the value of self raised to the power of self.

    Returns zero on underflow.

    // Get the value of the "amount" field raised to the power of 2.
    Field("amount").pow(2)
    

    Default Implementation

    Declaration

    Swift

    func pow(_ exponent: Sendable) -> FunctionExpression

    Parameters

    exponent

    The exponent to raise self to.

    Return Value

    A new FunctionExpression representing the power of the number.

  • pow(_:)

    Default implementation

    Creates an expression that returns the value of self raised to the power of self.

    Returns zero on underflow.

    // Get the value of the "amount" field raised to the power of the "exponent" field.
    Field("amount").pow(Field("exponent"))
    

    Default Implementation

    Declaration

    Swift

    func pow(_ exponent: Expression) -> FunctionExpression

    Parameters

    exponent

    The exponent to raise self to.

    Return Value

    A new FunctionExpression representing the power of the number.

  • ln()

    Default implementation

    Creates an expression that returns the natural logarithm of self.

    // Get the natural logarithm of the "amount" field.
    Field("amount").ln()
    

    Default Implementation

    Declaration

    Swift

    func ln() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the natural logarithm of the number.

  • floor()

    Default implementation

    Creates an expression that returns the largest numeric value that isn't greater than self.

    // Get the floor of the "amount" field.
    Field("amount").floor()
    

    Default Implementation

    Declaration

    Swift

    func floor() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the floor of the number.

  • exp()

    Default implementation

    Creates an expression that returns e to the power of self.

    Returns zero on underflow and nil on overflow.

    // Get the exp of the "amount" field.
    Field("amount").exp()
    

    Default Implementation

    Declaration

    Swift

    func exp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the exp of the number.

  • ceil()

    Default implementation

    Creates an expression that returns the smallest numeric value that isn't less than the number.

    // Get the ceiling of the "amount" field.
    Field("amount").ceil()
    

    Default Implementation

    Declaration

    Swift

    func ceil() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the ceiling of the number.

  • abs()

    Default implementation

    Creates an expression that returns the absolute value of the number.

    // Get the absolute value of the "amount" field.
    Field("amount").abs()
    

    Default Implementation

    Declaration

    Swift

    func abs() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the absolute value of the number.

  • trunc()

    Default implementation

    Creates an expression that returns the value of self truncated to an integer.

    // Get the value of the "rating" field truncated to an integer.
    Field("rating").trunc()
    

    Default Implementation

    Declaration

    Swift

    func trunc() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the truncated number.

  • truncToPrecision(_:)

    Default implementation

    Creates an expression that truncates self to a specified number of decimal places.

    If decimalPlace is positive, truncates number to the right of the decimal point. If decimalPlace is negative, truncates number to the left of the decimal point.

    // Truncate the value of the "rating" field to 2 decimal places.
    Field("rating").truncToPrecision(2)
    

    Default Implementation

    Declaration

    Swift

    func truncToPrecision(_ decimalPlace: Sendable) -> FunctionExpression

    Parameters

    decimalPlace

    The number of decimal places to truncate to.

    Return Value

    A new FunctionExpression representing the truncated number.

  • truncToPrecision(_:)

    Default implementation

    Creates an expression that truncates self to a specified number of decimal places.

    If decimalPlace is positive, truncates number to the right of the decimal point. If decimalPlace is negative, truncates number to the left of the decimal point.

    // Truncate the value of the "rating" field to the number of decimal places specified in the
    // "precision" field.
    Field("rating").truncToPrecision(Field("precision"))
    

    Default Implementation

    Declaration

    Swift

    func truncToPrecision(_ decimalPlace: Expression) -> FunctionExpression

    Parameters

    decimalPlace

    The number of decimal places to truncate to as an expression.

    Return Value

    A new FunctionExpression representing the truncated number.

  • add(_:)

    Default implementation

    Creates an expression that adds another expression to this expression. To add multiple expressions, chain calls to this method. Assumes self and the parameter evaluate to compatible types for addition (e.g., numbers, or string/array concatenation if supported by the specific "add" implementation).

    // Add the value of the "quantity" field and the "reserve" field.
    Field("quantity").add(Field("reserve"))
    
    // Add multiple numeric fields
    Field("subtotal").add(Field("tax")).add(Field("shipping"))
    

    Default Implementation

    Declaration

    Swift

    func add(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression to add.

    Return Value

    A new FunctionExpression representing the addition operation.

  • add(_:)

    Default implementation

    Creates an expression that adds a literal value to this expression. To add multiple literals, chain calls to this method. Assumes self and the parameter evaluate to compatible types for addition.

    // Add 5 to the "count" field
    Field("count").add(5)
    
    // Add multiple literal numbers
    Field("score").add(10).add(20).add(-5)
    

    Default Implementation

    Declaration

    Swift

    func add(_ value: Sendable) -> FunctionExpression

    Parameters

    value

    A Sendable literal value to add.

    Return Value

    A new FunctionExpression representing the addition operation.

  • subtract(_:)

    Default implementation

    Creates an expression that subtracts another expression from this expression. Assumes self and other evaluate to numeric types.

    // Subtract the "discount" field from the "price" field
    Field("price").subtract(Field("discount"))
    

    Default Implementation

    Declaration

    Swift

    func subtract(_ other: Expression) -> FunctionExpression

    Parameters

    other

    The Expression (evaluating to a number) to subtract from this expression.

    Return Value

    A new FunctionExpression representing the subtraction operation.

  • subtract(_:)

    Default implementation

    Creates an expression that subtracts a literal value from this expression. Assumes self evaluates to a numeric type.

    // Subtract 20 from the value of the "total" field
    Field("total").subtract(20)
    

    Default Implementation

    Declaration

    Swift

    func subtract(_ other: Sendable) -> FunctionExpression

    Parameters

    other

    The Sendable literal (numeric) value to subtract from this expression.

    Return Value

    A new FunctionExpression representing the subtraction operation.

  • multiply(_:)

    Default implementation

    Creates an expression that multiplies this expression by another expression. To multiply multiple expressions, chain calls to this method. Assumes self and the parameter evaluate to numeric types.

    // Multiply the "quantity" field by the "price" field
    Field("quantity").multiply(Field("price"))
    
    // Multiply "rate" by "time" and "conversionFactor" fields
    Field("rate").multiply(Field("time")).multiply(Field("conversionFactor"))
    

    Default Implementation

    Declaration

    Swift

    func multiply(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression to multiply by.

    Return Value

    A new FunctionExpression representing the multiplication operation.

  • multiply(_:)

    Default implementation

    Creates an expression that multiplies this expression by a literal value. To multiply multiple literals, chain calls to this method. Assumes self evaluates to a numeric type.

    // Multiply the "score" by 1.1
    Field("score").multiply(1.1)
    
    // Multiply "base" by 2 and then by 3.0
    Field("base").multiply(2).multiply(3.0)
    

    Default Implementation

    Declaration

    Swift

    func multiply(_ value: Sendable) -> FunctionExpression

    Parameters

    value

    A Sendable literal value to multiply by.

    Return Value

    A new FunctionExpression representing the multiplication operation.

  • divide(_:)

    Default implementation

    Creates an expression that divides this expression by another expression. Assumes self and other evaluate to numeric types.

    // Divide the "total" field by the "count" field
    Field("total").divide(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func divide(_ other: Expression) -> FunctionExpression

    Parameters

    other

    The Expression (evaluating to a number) to divide by.

    Return Value

    A new FunctionExpression representing the division operation.

  • divide(_:)

    Default implementation

    Creates an expression that divides this expression by a literal value. Assumes self evaluates to a numeric type.

    // Divide the "value" field by 10
    Field("value").divide(10)
    

    Default Implementation

    Declaration

    Swift

    func divide(_ other: Sendable) -> FunctionExpression

    Parameters

    other

    The Sendable literal (numeric) value to divide by.

    Return Value

    A new FunctionExpression representing the division operation.

  • mod(_:)

    Default implementation

    Creates an expression that calculates the modulo (remainder) of dividing this expression by another expression. Assumes self and other evaluate to numeric types.

    // Calculate the remainder of dividing the "value" field by the "divisor" field
    Field("value").mod(Field("divisor"))
    

    Default Implementation

    Declaration

    Swift

    func mod(_ other: Expression) -> FunctionExpression

    Parameters

    other

    The Expression (evaluating to a number) to use as the divisor.

    Return Value

    A new FunctionExpression representing the modulo operation.

  • mod(_:)

    Default implementation

    Creates an expression that calculates the modulo (remainder) of dividing this expression by a literal value. Assumes self evaluates to a numeric type.

    // Calculate the remainder of dividing the "value" field by 10
    Field("value").mod(10)
    

    Default Implementation

    Declaration

    Swift

    func mod(_ other: Sendable) -> FunctionExpression

    Parameters

    other

    The Sendable literal (numeric) value to use as the divisor.

    Return Value

    A new FunctionExpression representing the modulo operation.

  • arrayReverse()

    Default implementation

    Creates an expression that returns the input with elements in reverse order.

    // Reverse the "tags" array.
    Field("tags").arrayReverse()
    

    Default Implementation

    Declaration

    Swift

    func arrayReverse() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the reversed array.

  • arrayConcat(_:)

    Default implementation

    Creates an expression that concatenates an array expression (from self) with one or more other array expressions. Assumes self and all parameters evaluate to arrays.

    // Combine the "items" array with "otherItems" and "archiveItems" array fields.
    Field("items").arrayConcat(Field("otherItems"), Field("archiveItems"))
    

    Default Implementation

    Declaration

    Swift

    func arrayConcat(_ arrays: [Expression]) -> FunctionExpression

    Parameters

    arrays

    An array of at least one Expression (evaluating to an array) to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated array.

  • arrayConcat(_:)

    Default implementation

    Creates an expression that concatenates an array expression (from self) with one or more array literals. Assumes self evaluates to an array.

    // Combine "tags" (an array field) with ["new", "featured"] and ["urgent"]
    Field("tags").arrayConcat(["new", "featured"], ["urgent"])
    

    Default Implementation

    Declaration

    Swift

    func arrayConcat(_ arrays: [[Sendable]]) -> FunctionExpression

    Parameters

    arrays

    An array of at least one Sendable values to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated array.

  • arrayContains(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains a specific element expression. Assumes self evaluates to an array.

    // Check if "sizes" contains the value from "selectedSize" field
    Field("sizes").arrayContains(Field("selectedSize"))
    

    Default Implementation

    Declaration

    Swift

    func arrayContains(_ element: Expression) -> BooleanExpression

    Parameters

    element

    The Expression representing the element to search for in the array.

    Return Value

    A new BooleanExpr representing the "array_contains" comparison.

  • arrayContains(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains a specific literal element. Assumes self evaluates to an array.

    // Check if "colors" array contains "red"
    Field("colors").arrayContains("red")
    

    Default Implementation

    Declaration

    Swift

    func arrayContains(_ element: Sendable) -> BooleanExpression

    Parameters

    element

    The Sendable literal element to search for in the array.

    Return Value

    A new BooleanExpr representing the "array_contains" comparison.

  • arrayContainsAll(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains all the specified element expressions. Assumes self evaluates to an array.

    // Check if "candidateSkills" contains all skills from "requiredSkill1" and "requiredSkill2"
    fields
    Field("candidateSkills").arrayContainsAll([Field("requiredSkill1"), Field("requiredSkill2")])
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAll(_ values: [Expression]) -> BooleanExpression

    Parameters

    values

    A list of Expression elements to check for in the array represented by self.

    Return Value

    A new BooleanExpr representing the "array_contains_all" comparison.

  • arrayContainsAll(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains all the specified literal elements. Assumes self evaluates to an array.

    // Check if "tags" contains both "urgent" and "review"
    Field("tags").arrayContainsAll(["urgent", "review"])
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAll(_ values: [Sendable]) -> BooleanExpression

    Parameters

    values

    An array of at least one Sendable element to check for in the array.

    Return Value

    A new BooleanExpr representing the "array_contains_all" comparison.

  • arrayContainsAll(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains all the specified element expressions. Assumes self evaluates to an array.

    // Check if the "tags" array contains "foo", "bar", and "baz"
    Field("tags").arrayContainsAll(Constant(["foo", "bar", "baz"]))
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAll(_ arrayExpression: Expression) -> BooleanExpression

    Parameters

    values

    An Expression elements evaluated to be array.

    Return Value

    A new BooleanExpr representing the "array_contains_all" comparison.

  • arrayContainsAny(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains any of the specified element expressions. Assumes self evaluates to an array.

    // Check if "userGroups" contains any group from "allowedGroup1" or "allowedGroup2" fields
    Field("userGroups").arrayContainsAny([Field("allowedGroup1"), Field("allowedGroup2")])
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAny(_ values: [Expression]) -> BooleanExpression

    Parameters

    values

    A list of Expression elements to check for in the array.

    Return Value

    A new BooleanExpr representing the "array_contains_any" comparison.

  • arrayContainsAny(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains any of the specified literal elements. Assumes self evaluates to an array.

    // Check if "categories" contains either "electronics" or "books"
    Field("categories").arrayContainsAny(["electronics", "books"])
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAny(_ values: [Sendable]) -> BooleanExpression

    Parameters

    values

    An array of at least one Sendable element to check for in the array.

    Return Value

    A new BooleanExpr representing the "array_contains_any" comparison.

  • arrayContainsAny(_:)

    Default implementation

    Creates an expression that checks if an array (from self) contains any of the specified element expressions. Assumes self evaluates to an array.

    // Check if "groups" array contains any of the values from the "userGroup" field
    Field("groups").arrayContainsAny(Field("userGroup"))
    

    Default Implementation

    Declaration

    Swift

    func arrayContainsAny(_ arrayExpression: Expression) -> BooleanExpression

    Parameters

    arrayExpression

    An Expression elements evaluated to be array.

    Return Value

    A new BooleanExpr representing the "array_contains_any" comparison.

  • arrayLength()

    Default implementation

    Creates an expression that calculates the length of an array. Assumes self evaluates to an array.

    // Get the number of items in the "cart" array
    Field("cart").arrayLength()
    

    Default Implementation

    Declaration

    Swift

    func arrayLength() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the array.

  • arrayFilter(alias:filter:)

    Default implementation

    Filters an array to a subset of elements that match the provided condition. Assumes self evaluates to an array.

    // Filter the "items" array to include elements where "price" > 10
    Field("items").arrayFilter(alias: "item", filter: Variable("item.price").greaterThan(10))
    

    Default Implementation

    Declaration

    Swift

    func arrayFilter(alias: String, filter: BooleanExpression) -> FunctionExpression

    Parameters

    alias

    The variable name to be used in the filter expression to refer to the current array element.

    filter

    A BooleanExpression that determines whether an element is included.

    Return Value

    A new FunctionExpression representing the filtered array.

  • Creates an expression that applies a provided transformation to each element in an array. Assumes self evaluates to an array.

    // Transform the "scores" array by multiplying the "score" by 2
    Field("scores").arrayTransform(
      elementAlias: "score",
      transform: Variable("score").multiply(2)
    )
    

    Default Implementation

    Declaration

    Swift

    func arrayTransform(elementAlias: String, transform: Expression) -> FunctionExpression

    Parameters

    elementAlias

    The variable name to be used in the transform expression to refer to the current array element.

    transform

    A lambda Expression evaluated for each element to determine its new value.

    Return Value

    A new FunctionExpression representing the transformed array.

  • Creates an expression that applies a provided transformation to each element in an array, providing the element's index to the transformation expression. Assumes self evaluates to an array.

    // Transform the "scores" array by adding the element index and "name"
    Field("scores").arrayTransformWithIndex(
      elementAlias: "score",
      indexAlias: "index",
      transform: Variable("score").add(Variable("index"))
    )
    

    Default Implementation

    Declaration

    Swift

    func arrayTransformWithIndex(elementAlias: String, indexAlias: String, transform: Expression)
      -> FunctionExpression

    Parameters

    elementAlias

    The variable name to be used in the transform expression to refer to the current array element.

    indexAlias

    The variable name to be used in the transform expression to refer to the current element's zero-based index.

    transform

    A lambda Expression evaluated for each element to determine its new value.

    Return Value

    A new FunctionExpression representing the transformed array.

  • arraySlice(offset:)

    Default implementation

    Returns a subset of the array starting at the given offset. Assumes self evaluates to an array.

    // Get all elements from the "tags" array starting at index 1
    Field("tags").arraySlice(offset: 1)
    

    Default Implementation

    Declaration

    Swift

    func arraySlice(offset: Int) -> FunctionExpression

    Parameters

    offset

    The starting offset (integer).

    Return Value

    A new FunctionExpression representing the sliced array.

  • arraySlice(offset:)

    Default implementation

    Returns a subset of the array starting at the given offset. Assumes self evaluates to an array.

    // Get all elements from "tags" starting at an offset defined by a field
    Field("tags").arraySlice(offset: Field("startIdx"))
    

    Default Implementation

    Declaration

    Swift

    func arraySlice(offset: Expression) -> FunctionExpression

    Parameters

    offset

    An Expression (evaluating to an integer) for the starting offset.

    Return Value

    A new FunctionExpression representing the sliced array.

  • arraySlice(offset:length:)

    Default implementation

    Returns a subset of the array starting at the given offset, up to the given length. Assumes self evaluates to an array.

    // Get 2 elements from the "tags" array starting at index 1
    Field("tags").arraySlice(offset: 1, length: 2)
    

    Default Implementation

    Declaration

    Swift

    func arraySlice(offset: Int, length: Int) -> FunctionExpression

    Parameters

    offset

    The starting offset (integer).

    length

    The maximum length of the subset (positive integer).

    Return Value

    A new FunctionExpression representing the sliced array.

  • arraySlice(offset:length:)

    Default implementation

    Returns a subset of the array starting at the given offset, up to the given length. Assumes self evaluates to an array.

    // Get elements using expressions for offset and length
    Field("tags").arraySlice(offset: Field("startIdx"), length: Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func arraySlice(offset: Expression, length: Expression) -> FunctionExpression

    Parameters

    offset

    An Expression (evaluating to an integer) for the starting offset.

    length

    An Expression (evaluating to a positive integer) for the maximum length.

    Return Value

    A new FunctionExpression representing the sliced array.

  • arraySlice(offset:length:)

    Default implementation

    Returns a subset of the array starting at the given offset, up to the given length. Assumes self evaluates to an array.

    // Get n elements from the "tags" array starting at index 1
    Field("tags").arraySlice(offset: 1, length: Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func arraySlice(offset: Int, length: Expression) -> FunctionExpression

    Parameters

    offset

    The starting offset (integer).

    length

    An Expression (evaluating to a positive integer) for the maximum length.

    Return Value

    A new FunctionExpression representing the sliced array.

  • arraySlice(offset:length:)

    Default implementation

    Returns a subset of the array starting at the given offset, up to the given length. Assumes self evaluates to an array.

    // Get 2 elements from the "tags" array starting at an offset defined by a field
    Field("tags").arraySlice(offset: Field("startIdx"), length: 2)
    

    Default Implementation

    Declaration

    Swift

    func arraySlice(offset: Expression, length: Int) -> FunctionExpression

    Parameters

    offset

    An Expression (evaluating to an integer) for the starting offset.

    length

    The maximum length of the subset (positive integer).

    Return Value

    A new FunctionExpression representing the sliced array.

  • arrayFirst()

    Default implementation

    Creates an expression that returns the first element of an array. Assumes self evaluates to an array.

    // Get the first item in the "tags" array.
    Field("tags").arrayFirst()
    

    Default Implementation

    Declaration

    Swift

    func arrayFirst() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the first element of the array.

  • arrayFirstN(_:)

    Default implementation

    Creates an expression that returns the first n elements of an array. Assumes self evaluates to an array.

    // Get the first 3 items in the "tags" array.
    Field("tags").arrayFirstN(3)
    

    Default Implementation

    Declaration

    Swift

    func arrayFirstN(_ n: Int) -> FunctionExpression

    Parameters

    n

    The number of elements to return.

    Return Value

    A new FunctionExpression representing the first n elements of the array.

  • arrayFirstN(_:)

    Default implementation

    Creates an expression that returns the first n elements of an array. Assumes self evaluates to an array.

    // Get the first n items in the "tags" array where n is specified by field "count".
    Field("tags").arrayFirstN(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func arrayFirstN(_ n: Expression) -> FunctionExpression

    Parameters

    n

    An Expression (evaluating to an Int) representing the number of elements to return.

    Return Value

    A new FunctionExpression representing the first n elements of the array.

  • arrayLast()

    Default implementation

    Creates an expression that returns the last element of an array. Assumes self evaluates to an array.

    // Get the last item in the "tags" array.
    Field("tags").arrayLast()
    

    Default Implementation

    Declaration

    Swift

    func arrayLast() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the last element of the array.

  • arrayLastN(_:)

    Default implementation

    Creates an expression that returns the last n elements of an array. Assumes self evaluates to an array.

    // Get the last 3 items in the "tags" array.
    Field("tags").arrayLastN(3)
    

    Default Implementation

    Declaration

    Swift

    func arrayLastN(_ n: Int) -> FunctionExpression

    Parameters

    n

    The number of elements to return.

    Return Value

    A new FunctionExpression representing the last n elements of the array.

  • arrayLastN(_:)

    Default implementation

    Creates an expression that returns the last n elements of an array. Assumes self evaluates to an array.

    // Get the last n items in the "tags" array where n is specified by field "count".
    Field("tags").arrayLastN(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func arrayLastN(_ n: Expression) -> FunctionExpression

    Parameters

    n

    An Expression (evaluating to an Int) representing the number of elements to return.

    Return Value

    A new FunctionExpression representing the last n elements of the array.

  • arrayGet(_:)

    Default implementation

    Creates an expression that accesses an element in an array (from self) at the specified integer offset. A negative offset starts from the end. If the offset is out of bounds, an error may be returned during evaluation. Assumes self evaluates to an array.

    // Return the value in the "tags" field array at index 1.
    Field("tags").arrayGet(1)
    // Return the last element in the "tags" field array.
    Field("tags").arrayGet(-1)
    

    Default Implementation

    Declaration

    Swift

    func arrayGet(_ offset: Int) -> FunctionExpression

    Parameters

    offset

    The literal Int offset of the element to return.

    Return Value

    A new FunctionExpression representing the "arrayGet" operation.

  • arrayGet(_:)

    Default implementation

    Creates an expression that accesses an element in an array (from self) at the offset specified by an expression. A negative offset starts from the end. If the offset is out of bounds, an error may be returned during evaluation. Assumes self evaluates to an array and offsetExpr evaluates to an integer.

    // Return the value in the tags field array at index specified by field "favoriteTagIndex".
    Field("tags").arrayGet(Field("favoriteTagIndex"))
    

    Default Implementation

    Declaration

    Swift

    func arrayGet(_ offsetExpression: Expression) -> FunctionExpression

    Parameters

    offsetExpression

    An Expression (evaluating to an Int) representing the offset of the element to return.

    Return Value

    A new FunctionExpression representing the "arrayGet" operation.

  • arrayIndexOf(_:)

    Default implementation

    Creates an expression that returns the index of the first occurrence of a value in an array. Returns nil if the value is not found. Assumes self evaluates to an array.

    // Get the index of "urgent" in the "tags" array.
    Field("tags").arrayIndexOf("urgent")
    

    Default Implementation

    Declaration

    Swift

    func arrayIndexOf(_ value: Sendable) -> FunctionExpression

    Parameters

    value

    The literal Sendable value to search for.

    Return Value

    A new FunctionExpression representing the index of the value.

  • arrayIndexOf(_:)

    Default implementation

    Creates an expression that returns the index of the first occurrence of a value in an array. Returns nil if the value is not found. Assumes self evaluates to an array.

    // Get the index of the value of field "searchTag" in the "tags" array.
    Field("tags").arrayIndexOf(Field("searchTag"))
    

    Default Implementation

    Declaration

    Swift

    func arrayIndexOf(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression representing the value to search for.

    Return Value

    A new FunctionExpression representing the index of the value.

  • arrayLastIndexOf(_:)

    Default implementation

    Creates an expression that returns the index of the last occurrence of a value in an array. Returns nil if the value is not found. Assumes self evaluates to an array.

    // Get the last index of "urgent" in the "tags" array.
    Field("tags").arrayLastIndexOf("urgent")
    

    Default Implementation

    Declaration

    Swift

    func arrayLastIndexOf(_ value: Sendable) -> FunctionExpression

    Parameters

    value

    The literal Sendable value to search for.

    Return Value

    A new FunctionExpression representing the last index of the value.

  • arrayLastIndexOf(_:)

    Default implementation

    Creates an expression that returns the index of the last occurrence of a value in an array. Returns nil if the value is not found. Assumes self evaluates to an array.

    // Get the last index of the value of field "searchTag" in the "tags" array.
    Field("tags").arrayLastIndexOf(Field("searchTag"))
    

    Default Implementation

    Declaration

    Swift

    func arrayLastIndexOf(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression representing the value to search for.

    Return Value

    A new FunctionExpression representing the last index of the value.

  • arrayIndexOfAll(_:)

    Default implementation

    Creates an expression that returns all indices of a value in an array. Returns an empty array if the value is not found. Assumes self evaluates to an array.

    // Get all indices of "urgent" in the "tags" array.
    Field("tags").arrayIndexOfAll("urgent")
    

    Default Implementation

    Declaration

    Swift

    func arrayIndexOfAll(_ value: Sendable) -> FunctionExpression

    Parameters

    value

    The literal Sendable value to search for.

    Return Value

    A new FunctionExpression representing the indices of the value.

  • arrayIndexOfAll(_:)

    Default implementation

    Creates an expression that returns all indices of a value in an array. Returns an empty array if the value is not found. Assumes self evaluates to an array.

    // Get all indices of the value of field "searchTag" in the "tags" array.
    Field("tags").arrayIndexOfAll(Field("searchTag"))
    

    Default Implementation

    Declaration

    Swift

    func arrayIndexOfAll(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression representing the value to search for.

    Return Value

    A new FunctionExpression representing the indices of the value.

  • arrayMaximum()

    Default implementation

    Creates an expression that returns the maximum element of an array.

    Assumes self evaluates to an array.

    // Get the maximum value in the "scores" array.
    Field("scores").arrayMaximum()
    

    Default Implementation

    Declaration

    Swift

    func arrayMaximum() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the maximum element of the array.

  • arrayMinimum()

    Default implementation

    Creates an expression that returns the minimum element of an array.

    Assumes self evaluates to an array.

    // Get the minimum value in the "scores" array.
    Field("scores").arrayMinimum()
    

    Default Implementation

    Declaration

    Swift

    func arrayMinimum() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the minimum element of the array.

  • arrayMinimumN(_:)

    Default implementation

    Creates an expression that returns the n smallest elements of an array. Assumes self evaluates to an array.

    // Get the 3 lowest scores in the "scores" array.
    Field("scores").arrayMinimumN(3)
    

    Default Implementation

    Declaration

    Swift

    func arrayMinimumN(_ n: Int) -> FunctionExpression

    Parameters

    n

    The number of elements to return.

    Return Value

    A new FunctionExpression representing the n smallest elements of the array.

  • arrayMinimumN(_:)

    Default implementation

    Creates an expression that returns the n smallest elements of an array. Assumes self evaluates to an array.

    // Get the n lowest scores in the "scores" array where n is specified by field "count".
    Field("scores").arrayMinimumN(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func arrayMinimumN(_ n: Expression) -> FunctionExpression

    Parameters

    n

    An Expression (evaluating to an Int) representing the number of elements to return.

    Return Value

    A new FunctionExpression representing the n smallest elements of the array.

  • arrayMaximumN(_:)

    Default implementation

    Creates an expression that returns the n largest elements of an array. Assumes self evaluates to an array.

    // Get the 3 highest scores in the "scores" array.
    Field("scores").arrayMaximumN(3)
    

    Default Implementation

    Declaration

    Swift

    func arrayMaximumN(_ n: Int) -> FunctionExpression

    Parameters

    n

    The number of elements to return.

    Return Value

    A new FunctionExpression representing the n largest elements of the array.

  • arrayMaximumN(_:)

    Default implementation

    Creates an expression that returns the n largest elements of an array. Assumes self evaluates to an array.

    // Get the n highest scores in the "scores" array where n is specified by field "count".
    Field("scores").arrayMaximumN(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func arrayMaximumN(_ n: Expression) -> FunctionExpression

    Parameters

    n

    An Expression (evaluating to an Int) representing the number of elements to return.

    Return Value

    A new FunctionExpression representing the n largest elements of the array.

  • greaterThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than the given expression.

    Default Implementation

    Declaration

    Swift

    func greaterThan(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • greaterThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than the given value.

    Default Implementation

    Declaration

    Swift

    func greaterThan(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • greaterThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than or equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func greaterThanOrEqual(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • greaterThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is greater than or equal to the given value.

    Default Implementation

    Declaration

    Swift

    func greaterThanOrEqual(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than the given expression.

    Default Implementation

    Declaration

    Swift

    func lessThan(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThan(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than the given value.

    Default Implementation

    Declaration

    Swift

    func lessThan(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than or equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func lessThanOrEqual(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • lessThanOrEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is less than or equal to the given value.

    Default Implementation

    Declaration

    Swift

    func lessThanOrEqual(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equal(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func equal(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equal(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is equal to the given value.

    Default Implementation

    Declaration

    Swift

    func equal(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is not equal to the given expression.

    Default Implementation

    Declaration

    Swift

    func notEqual(_ other: Expression) -> BooleanExpression

    Parameters

    other

    The expression to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqual(_:)

    Default implementation

    Creates a BooleanExpression that returns true if this expression is not equal to the given value.

    Default Implementation

    Declaration

    Swift

    func notEqual(_ other: Sendable) -> BooleanExpression

    Parameters

    other

    The value to compare against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equalAny(_:)

    Default implementation

    Creates an expression that checks if this expression is equal to any of the provided expression values.

    // Check if "categoryID" field is equal to "featuredCategory" or "popularCategory" fields
    Field("categoryID").equalAny([Field("featuredCategory"), Field("popularCategory")])
    

    Default Implementation

    Declaration

    Swift

    func equalAny(_ others: [Expression]) -> BooleanExpression

    Parameters

    others

    An array of at least one Expression value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equalAny(_:)

    Default implementation

    Creates an expression that checks if this expression is equal to any of the provided literal values.

    // Check if "category" is "Electronics", "Books", or "Home Goods"
    Field("category").equalAny(["Electronics", "Books", "Home Goods"])
    

    Default Implementation

    Declaration

    Swift

    func equalAny(_ others: [Sendable]) -> BooleanExpression

    Parameters

    others

    An array of at least one Sendable literal value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • equalAny(_:)

    Default implementation

    Creates an expression that checks if this expression is equal to any of the provided expression values.

    // Check if "categoryID" field is equal to any of "categoryIDs" fields
    Field("categoryID").equalAny(Field("categoryIDs"))
    

    Default Implementation

    Declaration

    Swift

    func equalAny(_ arrayExpression: Expression) -> BooleanExpression

    Parameters

    arrayExpression

    An Expression elements evaluated to be array.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqualAny(_:)

    Default implementation

    Creates an expression that checks if this expression is not equal to any of the provided expression values.

    // Check if "statusValue" is not equal to "archivedStatus" or "deletedStatus" fields
    Field("statusValue").notEqualAny([Field("archivedStatus"), Field("deletedStatus")])
    

    Default Implementation

    Declaration

    Swift

    func notEqualAny(_ others: [Expression]) -> BooleanExpression

    Parameters

    others

    An array of at least one Expression value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqualAny(_:)

    Default implementation

    Creates an expression that checks if this expression is not equal to any of the provided literal values.

    // Check if "status" is neither "pending" nor "archived"
    Field("status").notEqualAny(["pending", "archived"])
    

    Default Implementation

    Declaration

    Swift

    func notEqualAny(_ others: [Sendable]) -> BooleanExpression

    Parameters

    others

    An array of at least one Sendable literal value to check against.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • notEqualAny(_:)

    Default implementation

    Creates an expression that checks if this expression is equal to any of the provided expression values.

    // Check if "categoryID" field is not equal to any of "categoryIDs" fields
    Field("categoryID").equalAny(Field("categoryIDs"))
    

    Default Implementation

    Declaration

    Swift

    func notEqualAny(_ arrayExpression: Expression) -> BooleanExpression

    Parameters

    arrayExpression

    An Expression elements evaluated to be array.

    Return Value

    A BooleanExpression that can be used in a where stage, together with other boolean expressions.

  • exists()

    Default implementation

    Creates an expression that checks if a field exists in the document.

    // Check if the document has a field named "phoneNumber"
    Field("phoneNumber").exists()
    

    Default Implementation

    Declaration

    Swift

    func exists() -> BooleanExpression

    Return Value

    A new BooleanExpression representing the "exists" check.

  • isError()

    Default implementation

    Creates an expression that checks if this expression produces an error during evaluation.

    // Check if accessing a non-existent array index causes an error
    Field("myArray").arrayGet(100).isError()
    

    Default Implementation

    Declaration

    Swift

    func isError() -> BooleanExpression

    Return Value

    A new BooleanExpression representing the "isError" check.

  • isAbsent()

    Default implementation

    Creates an expression that returns true if the result of this expression is absent (e.g., a field does not exist in a map). Otherwise, returns false.

    // Check if the field `value` is absent.
    Field("value").isAbsent()
    

    Default Implementation

    Declaration

    Swift

    func isAbsent() -> BooleanExpression

    Return Value

    A new BooleanExpression representing the "isAbsent" check.

  • join(delimiter:)

    Default implementation

    Creates an expression that joins the elements of an array of strings with a given separator.

    Assumes self evaluates to an array of strings.

    // Join the "tags" array with a ", " separator.
    Field("tags").join(separator: ", ")
    

    Default Implementation

    Declaration

    Swift

    func join(delimiter: String) -> FunctionExpression

    Parameters

    delimiter

    The string to use as a delimiter.

    Return Value

    A new FunctionExpression representing the joined string.

  • split(delimiter:)

    Default implementation

    Creates an expression that splits a string into an array of substrings based on a delimiter.

    Default Implementation

    Declaration

    Swift

    func split(delimiter: String) -> FunctionExpression

    Parameters

    delimiter

    The string to split on.

    Return Value

    A new FunctionExpression representing the array of substrings.

  • split(delimiter:)

    Default implementation

    Creates an expression that splits a string into an array of substrings based on a delimiter.

    Default Implementation

    Declaration

    Swift

    func split(delimiter: Expression) -> FunctionExpression

    Parameters

    delimiter

    An expression that evaluates to a string or bytes to split on.

    Return Value

    A new FunctionExpression representing the array of substrings.

  • length()

    Default implementation

    Creates an expression that returns the length of a string.

    // Get the length of the "name" field.
    Field("name").length()
    

    Default Implementation

    Declaration

    Swift

    func length() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the string.

  • charLength()

    Default implementation

    Creates an expression that calculates the character length of a string in UTF-8. Assumes self evaluates to a string.

    // Get the character length of the "name" field in its UTF-8 form.
    Field("name").charLength()
    

    Default Implementation

    Declaration

    Swift

    func charLength() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the string.

  • like(_:)

    Default implementation

    Creates an expression that performs a case-sensitive string comparison using wildcards against a literal pattern. Assumes self evaluates to a string.

    // Check if the "title" field contains the word "guide" (case-sensitive)
    Field("title").like("%guide%")
    

    Default Implementation

    Declaration

    Swift

    func like(_ pattern: String) -> BooleanExpression

    Parameters

    pattern

    The literal string pattern to search for. Use "%" as a wildcard.

    Return Value

    A new BooleanExpression representing the "like" comparison.

  • like(_:)

    Default implementation

    Creates an expression that performs a case-sensitive string comparison using wildcards against an expression pattern. Assumes self evaluates to a string, and pattern evaluates to a string.

    // Check if "filename" matches a pattern stored in "patternField"
    Field("filename").like(Field("patternField"))
    

    Default Implementation

    Declaration

    Swift

    func like(_ pattern: Expression) -> BooleanExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the pattern to search for.

    Return Value

    A new BooleanExpression representing the "like" comparison.

  • regexContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified regular expression literal as a substring. Assumes self evaluates to a string.

    // Check if "description" contains "example" (case-insensitive)
    Field("description").regexContains("(?i)example")
    

    Default Implementation

    Declaration

    Swift

    func regexContains(_ pattern: String) -> BooleanExpression

    Parameters

    pattern

    The literal string regular expression to use for the search.

    Return Value

    A new BooleanExpression representing the "regex_contains" comparison.

  • regexContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified regular expression (from an expression) as a substring. Assumes self evaluates to a string, and pattern evaluates to a string.

    // Check if "logEntry" contains a pattern from "errorPattern" field
    Field("logEntry").regexContains(Field("errorPattern"))
    

    Default Implementation

    Declaration

    Swift

    func regexContains(_ pattern: Expression) -> BooleanExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to use for the search.

    Return Value

    A new BooleanExpression representing the "regex_contains" comparison.

  • regexFind(_:)

    Default implementation

    Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes self evaluates to a string.

    // Extract the domain name from an email field
    Field("email").regexFind("@[A-Za-z0-9.-]+")
    

    Default Implementation

    Declaration

    Swift

    func regexFind(_ pattern: String) -> FunctionExpression

    Parameters

    pattern

    The literal string regular expression to search for.

    Return Value

    A new FunctionExpression representing the regular expression find function.

  • regexFind(_:)

    Default implementation

    Creates an expression that returns the first substring of a string expression that matches a specified regular expression. Assumes self evaluates to a string, and pattern evaluates to a string.

    // Extract a substring based on a dynamic pattern stored in another field
    Field("email").regexFind(Field("pattern"))
    

    Default Implementation

    Declaration

    Swift

    func regexFind(_ pattern: Expression) -> FunctionExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to search for.

    Return Value

    A new FunctionExpression representing the regular expression find function.

  • regexFindAll(_:)

    Default implementation

    Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes self evaluates to a string.

    // Extract all hashtags from a post content field
    Field("content").regexFindAll("#[A-Za-z0-9_]+")
    

    Default Implementation

    Declaration

    Swift

    func regexFindAll(_ pattern: String) -> FunctionExpression

    Parameters

    pattern

    The literal string regular expression to search for.

    Return Value

    A new FunctionExpression that evaluates to an array of matched substrings.

  • regexFindAll(_:)

    Default implementation

    Creates an expression that evaluates to a list of all substrings in a string expression that match a specified regular expression. Assumes self evaluates to a string, and pattern evaluates to a string.

    // Extract all matches based on a dynamic pattern stored in another field
    Field("content").regexFindAll(Field("pattern"))
    

    Default Implementation

    Declaration

    Swift

    func regexFindAll(_ pattern: Expression) -> FunctionExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to search for.

    Return Value

    A new FunctionExpression that evaluates to an array of matched substrings.

  • regexMatch(_:)

    Default implementation

    Creates an expression that checks if a string (from self) matches a specified regular expression literal entirely. Assumes self evaluates to a string.

    // Check if the "email" field matches a valid email pattern
    Field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}")
    

    Default Implementation

    Declaration

    Swift

    func regexMatch(_ pattern: String) -> BooleanExpression

    Parameters

    pattern

    The literal string regular expression to use for the match.

    Return Value

    A new BooleanExpression representing the regular expression match.

  • regexMatch(_:)

    Default implementation

    Creates an expression that checks if a string (from self) matches a specified regular expression (from an expression) entirely. Assumes self evaluates to a string, and pattern evaluates to a string.

    // Check if "input" matches the regex stored in "validationRegex"
    Field("input").regexMatch(Field("validationRegex"))
    

    Default Implementation

    Declaration

    Swift

    func regexMatch(_ pattern: Expression) -> BooleanExpression

    Parameters

    pattern

    An Expression (evaluating to a string) representing the regular expression to use for the match.

    Return Value

    A new BooleanExpression representing the regular expression match.

  • stringContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified literal substring (case-sensitive). Assumes self evaluates to a string.

    // Check if the "description" field contains "example".
    Field("description").stringContains("example")
    

    Default Implementation

    Declaration

    Swift

    func stringContains(_ substring: String) -> BooleanExpression

    Parameters

    substring

    The literal string substring to search for.

    Return Value

    A new BooleanExpression representing the "stringContains" comparison.

  • stringContains(_:)

    Default implementation

    Creates an expression that checks if a string (from self) contains a specified substring from an expression (case-sensitive). Assumes self evaluates to a string, and expression evaluates to a string.

    // Check if the "message" field contains the value of the "keyword" field.
    Field("message").stringContains(Field("keyword"))
    

    Default Implementation

    Declaration

    Swift

    func stringContains(_ expression: Expression) -> BooleanExpression

    Parameters

    expression

    An Expression (evaluating to a string) representing the substring to search for.

    Return Value

    A new BooleanExpression representing the "str_contains" comparison.

  • startsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) starts with a given literal prefix (case-sensitive). Assumes self evaluates to a string.

    // Check if the "name" field starts with "Mr."
    Field("name").startsWith("Mr.")
    

    Default Implementation

    Declaration

    Swift

    func startsWith(_ prefix: String) -> BooleanExpression

    Parameters

    prefix

    The literal string prefix to check for.

    Return Value

    A new BooleanExpr representing the "starts_with" comparison.

  • startsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) starts with a given prefix from an expression (case-sensitive). Assumes self evaluates to a string, and prefix evaluates to a string.

    // Check if "fullName" starts with the value of "firstName"
    Field("fullName").startsWith(Field("firstName"))
    

    Default Implementation

    Declaration

    Swift

    func startsWith(_ prefix: Expression) -> BooleanExpression

    Parameters

    prefix

    An Expression (evaluating to a string) representing the prefix to check for.

    Return Value

    A new BooleanExpr representing the "starts_with" comparison.

  • endsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) ends with a given literal suffix (case-sensitive). Assumes self evaluates to a string.

    // Check if the "filename" field ends with ".txt"
    Field("filename").endsWith(".txt")
    

    Default Implementation

    Declaration

    Swift

    func endsWith(_ suffix: String) -> BooleanExpression

    Parameters

    suffix

    The literal string suffix to check for.

    Return Value

    A new BooleanExpr representing the "ends_with" comparison.

  • endsWith(_:)

    Default implementation

    Creates an expression that checks if a string (from self) ends with a given suffix from an expression (case-sensitive). Assumes self evaluates to a string, and suffix evaluates to a string.

    // Check if "url" ends with the value of "extension" field
    Field("url").endsWith(Field("extension"))
    

    Default Implementation

    Declaration

    Swift

    func endsWith(_ suffix: Expression) -> BooleanExpression

    Parameters

    suffix

    An Expression (evaluating to a string) representing the suffix to check for.

    Return Value

    A new BooleanExpression representing the "ends_with" comparison.

  • toLower()

    Default implementation

    Creates an expression that converts a string (from self) to lowercase. Assumes self evaluates to a string.

    // Convert the "name" field to lowercase
    Field("name").toLower()
    

    Default Implementation

    Declaration

    Swift

    func toLower() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the lowercase string.

  • toUpper()

    Default implementation

    Creates an expression that converts a string (from self) to uppercase. Assumes self evaluates to a string.

    // Convert the "title" field to uppercase
    Field("title").toUpper()
    

    Default Implementation

    Declaration

    Swift

    func toUpper() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the uppercase string.

  • trim()

    Default implementation

    Creates an expression that removes leading and trailing whitespace from a string.

    Assumes self evaluates to a string.

    // Trim leading/trailing whitespace from the "comment" field.
    Field("comment").trim()
    

    Default Implementation

    Declaration

    Swift

    func trim() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the trimmed string.

  • trim(_:)

    Default implementation

    Creates an expression that removes leading and trailing occurrences of specified characters from a string (from self). Assumes self evaluates to a string, and value evaluates to a string.

    // Trim leading/trailing "xy" from field
    Field("code").trim(characters: "xy")
    

    Default Implementation

    Declaration

    Swift

    func trim(_ value: String) -> FunctionExpression

    Parameters

    value

    A String containing the characters to trim.

    Return Value

    A new FunctionExpression representing the trimmed string.

  • trim(_:)

    Default implementation

    Creates an expression that removes leading and trailing occurrences of specified string (from an expression) from a string (from self). Assumes self evaluates to a string, and value evaluates to a string.

    // Trim characters specified by the "trimChars" field from "data"
    Field("data").trim(characters: Field("trimChars"))
    

    Default Implementation

    Declaration

    Swift

    func trim(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression (evaluating to a string) containing the characters to trim.

    Return Value

    A new FunctionExpression representing the trimmed string.

  • ltrim()

    Default implementation

    Creates an expression that removes leading whitespace from this string expression. Assumes self evaluates to a string.

    // Trim leading whitespace from the "text" field.
    Field("text").ltrim()
    

    Default Implementation

    Declaration

    Swift

    func ltrim() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the ltrim operation.

  • ltrim(_:)

    Default implementation

    Creates an expression that removes specified leading characters from this string expression. Assumes self evaluates to a string, and value evaluates to a string.

    The characters in value are treated as a set of characters to trim, not as a substring.

    // Trim all leading '-' or '_' characters from the "text" field.
    Field("text").ltrim("-_")
    

    Default Implementation

    Declaration

    Swift

    func ltrim(_ value: String) -> FunctionExpression

    Parameters

    value

    The literal string of characters to remove.

    Return Value

    A new FunctionExpression representing the ltrim operation.

  • ltrim(_:)

    Default implementation

    Creates an expression that removes specified leading characters from this string expression. Assumes self evaluates to a string, and value evaluates to a string.

    The characters in value are treated as a set of characters to trim, not as a substring.

    // Trim leading characters defined by the "chars" field from the "text" field.
    Field("text").ltrim(Field("chars"))
    

    Default Implementation

    Declaration

    Swift

    func ltrim(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression (evaluating to a string) representing the characters to remove.

    Return Value

    A new FunctionExpression representing the ltrim operation.

  • rtrim()

    Default implementation

    Creates an expression that removes trailing whitespace from this string expression. Assumes self evaluates to a string.

    // Trim trailing whitespace from the "text" field.
    Field("text").rtrim()
    

    Default Implementation

    Declaration

    Swift

    func rtrim() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the rtrim operation.

  • rtrim(_:)

    Default implementation

    Creates an expression that removes specified trailing characters from this string expression. Assumes self evaluates to a string, and value evaluates to a string.

    The characters in value are treated as a set of characters to trim, not as a substring.

    // Trim trailing '-' or '_' characters from the "text" field.
    Field("text").rtrim("-_")
    

    Default Implementation

    Declaration

    Swift

    func rtrim(_ value: String) -> FunctionExpression

    Parameters

    value

    The literal string of characters to remove.

    Return Value

    A new FunctionExpression representing the rtrim operation.

  • rtrim(_:)

    Default implementation

    Creates an expression that removes specified trailing characters from this string expression. Assumes self evaluates to a string, and value evaluates to a string.

    The characters in value are treated as a set of characters to trim, not as a substring.

    // Trim trailing characters defined by the "chars" field from the "text" field.
    Field("text").rtrim(Field("chars"))
    

    Default Implementation

    Declaration

    Swift

    func rtrim(_ value: Expression) -> FunctionExpression

    Parameters

    value

    An Expression (evaluating to a string) representing the characters to remove.

    Return Value

    A new FunctionExpression representing the rtrim operation.

  • stringRepeat(_:)

    Default implementation

    Creates an expression that repeats this string expression a given number of times. Assumes self evaluates to a string.

    // Repeat the "name" field 3 times.
    Field("name").stringRepeat(3)
    

    Default Implementation

    Declaration

    Swift

    func stringRepeat(_ count: Int) -> FunctionExpression

    Parameters

    count

    The literal Int number of times to repeat the string.

    Return Value

    A new FunctionExpression representing the stringRepeat operation.

  • stringRepeat(_:)

    Default implementation

    Creates an expression that repeats this string expression a given number of times. Assumes self evaluates to a string.

    // Repeat the "name" field the number of times specified in the "count" field.
    Field("name").stringRepeat(Field("count"))
    

    Default Implementation

    Declaration

    Swift

    func stringRepeat(_ count: Expression) -> FunctionExpression

    Parameters

    count

    An Expression (evaluating to an Int) representing the number of times to repeat the string.

    Return Value

    A new FunctionExpression representing the stringRepeat operation.

  • stringReplaceAll(_:with:)

    Default implementation

    Creates an expression that replaces all occurrences of a literal substring with another literal string. Assumes self evaluates to a string.

    // Replace all occurrences of "cat" with "dog" in the "text" field.
    Field("text").stringReplaceAll("cat", with: "dog")
    

    Default Implementation

    Declaration

    Swift

    func stringReplaceAll(_ oldValue: String, with newValue: String) -> FunctionExpression

    Parameters

    oldValue

    The literal string substring to replace.

    newValue

    The literal replacement string.

    Return Value

    A new FunctionExpression representing the stringReplaceAll operation.

  • stringReplaceAll(_:with:)

    Default implementation

    Creates an expression that replaces all occurrences of a substring (from an expression) with another string. Assumes self evaluates to a string.

    // Replace all occurrences of the "old" field with the "new" field in "text".
    Field("text").stringReplaceAll(Field("old"), with: Field("new"))
    

    Default Implementation

    Declaration

    Swift

    func stringReplaceAll(_ oldValue: Expression, with newValue: Expression) -> FunctionExpression

    Parameters

    oldValue

    An Expression (evaluating to a string) representing the substring to replace.

    newValue

    An Expression (evaluating to a string) representing the replacement string.

    Return Value

    A new FunctionExpression representing the stringReplaceAll operation.

  • stringReplaceOne(_:with:)

    Default implementation

    Creates an expression that replaces the first occurrence of a literal substring with another literal string. Assumes self evaluates to a string.

    // Replace the first occurrence of "cat" with "dog" in the "text" field.
    Field("text").stringReplaceOne("cat", with: "dog")
    

    Default Implementation

    Declaration

    Swift

    func stringReplaceOne(_ oldValue: String, with newValue: String) -> FunctionExpression

    Parameters

    oldValue

    The literal string substring to replace.

    newValue

    The literal replacement string.

    Return Value

    A new FunctionExpression representing the stringReplaceOne operation.

  • stringReplaceOne(_:with:)

    Default implementation

    Creates an expression that replaces the first occurrence of a substring (from an expression) with another string. Assumes self evaluates to a string.

    // Replace the first occurrence of the "old" field with the "new" field in "text".
    Field("text").stringReplaceOne(Field("old"), with: Field("new"))
    

    Default Implementation

    Declaration

    Swift

    func stringReplaceOne(_ oldValue: Expression, with newValue: Expression) -> FunctionExpression

    Parameters

    oldValue

    An Expression (evaluating to a string) representing the substring to replace.

    newValue

    An Expression (evaluating to a string) representing the replacement string.

    Return Value

    A new FunctionExpression representing the stringReplaceOne operation.

  • stringIndexOf(_:)

    Default implementation

    Creates an expression that returns the 0-based index of the first occurrence of a literal substring. Assumes self evaluates to a string.

    // Get the index of "world" within the "text" field.
    Field("text").stringIndexOf("world")
    

    Default Implementation

    Declaration

    Swift

    func stringIndexOf(_ substring: String) -> FunctionExpression

    Parameters

    substring

    The literal string substring to search for.

    Return Value

    A new FunctionExpression representing the stringIndexOf operation.

  • stringIndexOf(_:)

    Default implementation

    Creates an expression that returns the 0-based index of the first occurrence of a substring (from an expression). Assumes self evaluates to a string.

    // Get the index of the "search" field within the "text" field.
    Field("text").stringIndexOf(Field("search"))
    

    Default Implementation

    Declaration

    Swift

    func stringIndexOf(_ substring: Expression) -> FunctionExpression

    Parameters

    substring

    An Expression (evaluating to a string) representing the substring to search for.

    Return Value

    A new FunctionExpression representing the stringIndexOf operation.

  • stringConcat(_:)

    Default implementation

    Creates an expression that concatenates this string expression with other string expressions. Assumes self and all parameters evaluate to strings.

    // Combine "firstName", " ", and "lastName"
    Field("firstName").stringConcat([" ", Field("lastName")])
    

    Default Implementation

    Declaration

    Swift

    func stringConcat(_ strings: [Sendable]) -> FunctionExpression

    Parameters

    strings

    An array of Expression or String to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated string.

  • stringConcat(_:)

    Default implementation

    Creates an expression that concatenates this string expression with other string expressions. Assumes self and all parameters evaluate to strings.

    // Combine "firstName", "middleName", and "lastName" fields
    Field("firstName").stringConcat(Field("middleName"), Field("lastName"))
    

    Default Implementation

    Declaration

    Swift

    func stringConcat(_ strings: [Expression]) -> FunctionExpression

    Parameters

    secondString

    An Expression (evaluating to a string) to concatenate.

    otherStrings

    Optional additional Expression (evaluating to strings) to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated string.

  • reverse()

    Default implementation

    Creates an expression that reverses this expression. Assumes self evaluates to a string.

    // Reverse the value of the "myString" field.
    Field("myString").reverse()
    

    Default Implementation

    Declaration

    Swift

    func reverse() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the reversed string.

  • stringReverse()

    Default implementation

    Creates an expression that reverses this string expression. Assumes self evaluates to a string.

    // Reverse the value of the "myString" field.
    Field("myString").stringReverse()
    

    Default Implementation

    Declaration

    Swift

    func stringReverse() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the reversed string.

  • byteLength()

    Default implementation

    Creates an expression that calculates the length of this string or bytes expression in bytes. Assumes self evaluates to a string or bytes.

    // Calculate the length of the "myString" field in bytes.
    Field("myString").byteLength()
    
    // Calculate the size of the "avatar" (Data/Bytes) field.
    Field("avatar").byteLength()
    

    Default Implementation

    Declaration

    Swift

    func byteLength() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length in bytes.

  • substring(position:length:)

    Default implementation

    Creates an expression that returns a substring of this expression (String or Bytes) using literal integers for position and optional length. Indexing is 0-based. Assumes self evaluates to a string or bytes.

    // Get substring from index 5 with length 10
    Field("myString").substring(5, 10)
    
    // Get substring from "myString" starting at index 3 to the end
    Field("myString").substring(3) // Default nil
    

    Default Implementation

    Declaration

    Swift

    func substring(position: Int, length: Int?) -> FunctionExpression

    Parameters

    position

    Literal Int index of the first character/byte.

    length

    Optional literal Int length of the substring. If nil, goes to the end.

    Return Value

    A new FunctionExpression representing the substring.

  • substring(position:length:)

    Default implementation

    Creates an expression that returns a substring of this expression (String or Bytes) using expressions for position and optional length. Indexing is 0-based. Assumes self evaluates to a string or bytes, and parameters evaluate to integers.

    // Get substring from index calculated by Field("start") with length from Field("len")
    Field("myString").substring(Field("start"), Field("len"))
    
    // Get substring from index calculated by Field("start") to the end
    Field("myString").substring(Field("start")) // Default nil for optional Expression length
    

    Default Implementation

    Declaration

    Swift

    func substring(position: Expression, length: Expression?) -> FunctionExpression

    Parameters

    position

    An Expression (evaluating to an Int) for the index of the first character.

    length

    Optional Expression (evaluating to an Int) for the length of the substring. If nil, goes to the end.

    Return Value

    A new FunctionExpression representing the substring.

  • getField(_:)

    Default implementation

    Creates an expression that accesses a field on this expression using a string key.

    Default Implementation

    Creates an expression that accesses a field on this expression using a string key.

    Declaration

    Swift

    func getField(_ key: String) -> FunctionExpression

    Parameters

    key

    The string key to access.

    Return Value

    A new FunctionExpression representing the field access.

  • getField(_:)

    Default implementation

    Creates an expression that accesses a field on this expression using a dynamic key expression.

    Default Implementation

    Creates an expression that accesses a field on this expression using a dynamic key expression.

    Declaration

    Swift

    func getField(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The expression evaluating to a key to access.

    Return Value

    A new FunctionExpression representing the field access.

  • mapGet(_:)

    Default implementation

    Accesses a value from a map (object) field using the provided literal string key. Assumes self evaluates to a Map.

    // Get the "city" value from the "address" map field
    Field("address").mapGet("city")
    

    Default Implementation

    Declaration

    Swift

    func mapGet(_ subfield: String) -> FunctionExpression

    Parameters

    subfield

    The literal string key to access in the map.

    Return Value

    A new FunctionExpression representing the value associated with the given key.

  • mapRemove(_:)

    Default implementation

    Creates an expression that removes a key (specified by a literal string) from the map produced by evaluating this expression. Assumes self evaluates to a Map.

    // Removes the key "baz" from the map held in field "myMap"
    Field("myMap").mapRemove("baz")
    

    Default Implementation

    Declaration

    Swift

    func mapRemove(_ key: String) -> FunctionExpression

    Parameters

    key

    The literal string key to remove from the map.

    Return Value

    A new FunctionExpression representing the "map_remove" operation.

  • mapRemove(_:)

    Default implementation

    Creates an expression that removes a key (specified by an expression) from the map produced by evaluating this expression. Assumes self evaluates to a Map, and keyExpression evaluates to a string.

    // Removes the key specified by field "keyToRemove" from the map in "settings"
    Field("settings").mapRemove(Field("keyToRemove"))
    

    Default Implementation

    Declaration

    Swift

    func mapRemove(_ keyExpression: Expression) -> FunctionExpression

    Parameters

    keyExpression

    An Expression (evaluating to a string) representing the key to remove from the map.

    Return Value

    A new FunctionExpression representing the "map_remove" operation.

  • mapMerge(_:)

    Default implementation

    Creates an expression that merges this map with multiple other map literals. Assumes self evaluates to a Map. Later maps overwrite keys from earlier maps.

    // Merge "settings" field with { "enabled": true } and another map literal { "priority": 1 }
    Field("settings").mapMerge(["enabled": true], ["priority": 1])
    

    Default Implementation

    Declaration

    Swift

    func mapMerge(_ maps: [[String: Sendable]])
      -> FunctionExpression

    Parameters

    maps

    Maps (dictionary literals with Sendable values) to merge.

    Return Value

    A new FunctionExpression representing the "map_merge" operation.

  • mapMerge(_:)

    Default implementation

    Creates an expression that merges this map with multiple other map expressions. Assumes self and other arguments evaluate to Maps. Later maps overwrite keys from earlier maps.

    // Merge "baseSettings" field with "userOverrides" field and "adminConfig" field
    Field("baseSettings").mapMerge(Field("userOverrides"), Field("adminConfig"))
    

    Default Implementation

    Declaration

    Swift

    func mapMerge(_ maps: [Expression]) -> FunctionExpression

    Parameters

    maps

    Additional Expression (evaluating to Maps) to merge.

    Return Value

    A new FunctionExpression representing the "map_merge" operation.

  • mapSet(_:_:_:)

    Default implementation

    Creates an expression that returns a new map with the specified entries added or updated. Assumes self evaluates to a Map.

    • Only performs shallow updates to the map.
    • Setting a value to nil will retain the key with a nil value. To remove a key entirely, use mapRemove.
    // Set the 'category' key to the value of the 'newCategory' field.
    Field("metadata").mapSet(Field("keyField"), Field("newCategory"))
    

    Default Implementation

    Declaration

    Swift

    func mapSet(_ key: Expression, _ value: Expression, _ moreKeyValues: Expression...)
      -> FunctionExpression

    Parameters

    key

    An Expression representing the key to set.

    value

    An Expression representing the value to set.

    moreKeyValues

    Additional alternating key-value Expression pairs to set.

    Return Value

    A new FunctionExpression representing the map with the entries set.

  • mapSet(_:_:_:)

    Default implementation

    Creates an expression that returns a new map with the specified entries added or updated. Assumes self evaluates to a Map.

    • Only performs shallow updates to the map.
    • Setting a value to nil will retain the key with a nil value. To remove a key entirely, use mapRemove.
    // Set the 'category' key to "Electronics" and 'active' to true.
    Field("metadata").mapSet("category", "Electronics", "active", true)
    

    Default Implementation

    Declaration

    Swift

    func mapSet(_ key: String, _ value: Sendable, _ moreKeyValues: Sendable...) -> FunctionExpression

    Parameters

    key

    A literal string key to set.

    value

    A Sendable value to set.

    moreKeyValues

    Additional alternating key-value Sendable pairs to set.

    Return Value

    A new FunctionExpression representing the map with the entries set.

  • mapKeys()

    Default implementation

    Creates an expression that returns the keys of this map expression. Assumes self evaluates to a Map.

    While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.

    // Get the keys of the 'metadata' map field.
    Field("metadata").mapKeys()
    

    Default Implementation

    Declaration

    Swift

    func mapKeys() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the keys of the map.

  • mapValues()

    Default implementation

    Creates an expression that returns the values of this map expression. Assumes self evaluates to a Map.

    While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.

    // Get the values of the 'metadata' map field.
    Field("metadata").mapValues()
    

    Default Implementation

    Declaration

    Swift

    func mapValues() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the values of the map.

  • mapEntries()

    Default implementation

    Creates an expression that returns the entries of this map expression as an array of maps, where each map contains a "k" property for the key and a "v" property for the value. Assumes self evaluates to a Map.

    While the backend generally preserves insertion order, relying on the order of the output array is not guaranteed and should be avoided.

    // Get the entries of the 'metadata' map field.
    Field("metadata").mapEntries()
    

    Default Implementation

    Declaration

    Swift

    func mapEntries() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the entries of the map.

  • countDistinct()

    Default implementation

    Creates an aggregation that counts the number of distinct values of this expression.

    // Count the number of distinct categories.
    Field("category").countDistinct().as("distinctCategories")
    

    Default Implementation

    Declaration

    Swift

    func countDistinct() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "count_distinct" aggregation.

  • count()

    Default implementation

    Creates an aggregation that counts the number of stage inputs where this expression evaluates to a valid, non-null value.

    // Count the total number of products with a "productId"
    Field("productId").count().alias("totalProducts")
    

    Default Implementation

    Declaration

    Swift

    func count() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "count" aggregation on this expression.

  • sum()

    Default implementation

    Creates an aggregation that calculates the sum of this numeric expression across multiple stage inputs. Assumes self evaluates to a numeric type.

    // Calculate the total revenue from a set of orders
    Field("orderAmount").sum().alias("totalRevenue")
    

    Default Implementation

    Declaration

    Swift

    func sum() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "sum" aggregation.

  • average()

    Default implementation

    Creates an aggregation that calculates the average (mean) of this numeric expression across multiple stage inputs. Assumes self evaluates to a numeric type.

    // Calculate the average age of users
    Field("age").average().as("averageAge")
    

    Default Implementation

    Declaration

    Swift

    func average() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "average" aggregation.

  • minimum()

    Default implementation

    Creates an aggregation that finds the minimum value of this expression across multiple stage inputs.

    // Find the lowest price of all products
    Field("price").minimum().alias("lowestPrice")
    

    Default Implementation

    Declaration

    Swift

    func minimum() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "min" aggregation.

  • maximum()

    Default implementation

    Creates an aggregation that finds the maximum value of this expression across multiple stage inputs.

    // Find the highest score in a leaderboard
    Field("score").maximum().alias("highestScore")
    

    Default Implementation

    Declaration

    Swift

    func maximum() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "max" aggregation.

  • first()

    Default implementation

    Creates an aggregation that finds the first value of this expression across multiple stage inputs.

    // Find the first rating
    Field("rating").first().as("firstRating")
    

    Default Implementation

    Declaration

    Swift

    func first() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "first" aggregation.

  • last()

    Default implementation

    Creates an aggregation that finds the last value of this expression across multiple stage inputs.

    // Find the last rating
    Field("rating").last().as("lastRating")
    

    Default Implementation

    Declaration

    Swift

    func last() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "last" aggregation.

  • arrayAgg()

    Default implementation

    Creates an aggregation that collects all values of this expression across multiple stage inputs into an array.

    If the expression resolves to an absent value, it is converted to null. The order of elements in the output array is not stable and shouldn't be relied upon.

    // Collect all tags into an array
    Field("tags").arrayAgg().as("allTags")
    

    Default Implementation

    Declaration

    Swift

    func arrayAgg() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "array_agg" aggregation.

  • arrayAggDistinct()

    Default implementation

    Creates an aggregation that collects all distinct values of this expression across multiple stage inputs into an array.

    If the expression resolves to an absent value, it is converted to null. The order of elements in the output array is not stable and shouldn't be relied upon.

    // Collect all distinct tags into an array
    Field("tags").arrayAggDistinct().as("allDistinctTags")
    

    Default Implementation

    Declaration

    Swift

    func arrayAggDistinct() -> AggregateFunction

    Return Value

    A new AggregateFunction representing the "array_agg_distinct" aggregation.

  • logicalMaximum(_:)

    Default implementation

    Creates an expression that returns the larger value between this expression and other expressions, based on Firestore"s value type ordering.

    // Returns the largest of "val1", "val2", and "val3" fields
    Field("val1").logicalMaximum(Field("val2"), Field("val3"))
    

    Default Implementation

    Declaration

    Swift

    func logicalMaximum(_ expressions: [Expression]) -> FunctionExpression

    Parameters

    expressions

    An array of at least one Expression to compare with.

    Return Value

    A new FunctionExpression representing the logical max operation.

  • logicalMaximum(_:)

    Default implementation

    Creates an expression that returns the larger value between this expression and other literal values, based on Firestore"s value type ordering.

    // Returns the largest of "val1" (a field), 100, and 200.0
    Field("val1").logicalMaximum(100, 200.0)
    

    Default Implementation

    Declaration

    Swift

    func logicalMaximum(_ values: [Sendable]) -> FunctionExpression

    Parameters

    values

    An array of at least one Sendable value to compare with.

    Return Value

    A new FunctionExpression representing the logical max operation.

  • logicalMinimum(_:)

    Default implementation

    Creates an expression that returns the smaller value between this expression and other expressions, based on Firestore"s value type ordering.

    // Returns the smallest of "val1", "val2", and "val3" fields
    Field("val1").logicalMinimum(Field("val2"), Field("val3"))
    

    Default Implementation

    Declaration

    Swift

    func logicalMinimum(_ expressions: [Expression]) -> FunctionExpression

    Parameters

    expressions

    An array of at least one Expression to compare with.

    Return Value

    A new FunctionExpression representing the logical min operation.

  • logicalMinimum(_:)

    Default implementation

    Creates an expression that returns the smaller value between this expression and other literal values, based on Firestore"s value type ordering.

    // Returns the smallest of "val1" (a field), 0, and -5.5
    Field("val1").logicalMinimum(0, -5.5)
    

    Default Implementation

    Declaration

    Swift

    func logicalMinimum(_ values: [Sendable]) -> FunctionExpression

    Parameters

    values

    An array of at least one Sendable value to compare with.

    Return Value

    A new FunctionExpression representing the logical min operation.

  • vectorLength()

    Default implementation

    Creates an expression that calculates the length (number of dimensions) of this Firestore Vector expression. Assumes self evaluates to a Vector.

    // Get the vector length (dimension) of the field "embedding".
    Field("embedding").vectorLength()
    

    Default Implementation

    Declaration

    Swift

    func vectorLength() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the length of the vector.

  • cosineDistance(_:)

    Default implementation

    Calculates the cosine distance between this vector expression and another vector expression. Assumes both self and other evaluate to Vectors.

    // Cosine distance between "userVector" field and "itemVector" field
    Field("userVector").cosineDistance(Field("itemVector"))
    

    Default Implementation

    Declaration

    Swift

    func cosineDistance(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The other vector as an Expr to compare against.

    Return Value

    A new FunctionExpression representing the cosine distance.

  • cosineDistance(_:)

    Default implementation

    Calculates the cosine distance between this vector expression and another vector literal (VectorValue). Assumes self evaluates to a Vector.

    // Cosine distance with a VectorValue
    let targetVector = VectorValue(vector: [0.1, 0.2, 0.3])
    Field("docVector").cosineDistance(targetVector)
    

    Default Implementation

    Declaration

    Swift

    func cosineDistance(_ vector: VectorValue) -> FunctionExpression

    Parameters

    vector

    The other vector as a VectorValue to compare against.

    Return Value

    A new FunctionExpression representing the cosine distance.

  • cosineDistance(_:)

    Default implementation

    Calculates the cosine distance between this vector expression and another vector literal ([Double]). Assumes self evaluates to a Vector.

    // Cosine distance between "location" field and a target location
    Field("location").cosineDistance([37.7749, -122.4194])
    

    Default Implementation

    Declaration

    Swift

    func cosineDistance(_ vector: [Double]) -> FunctionExpression

    Parameters

    vector

    The other vector as [Double] to compare against.

    Return Value

    A new FunctionExpression representing the cosine distance.

  • dotProduct(_:)

    Default implementation

    Calculates the dot product between this vector expression and another vector expression. Assumes both self and other evaluate to Vectors.

    // Dot product between "vectorA" and "vectorB" fields
    Field("vectorA").dotProduct(Field("vectorB"))
    

    Default Implementation

    Declaration

    Swift

    func dotProduct(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The other vector as an Expr to calculate with.

    Return Value

    A new FunctionExpression representing the dot product.

  • dotProduct(_:)

    Default implementation

    Calculates the dot product between this vector expression and another vector literal (VectorValue). Assumes self evaluates to a Vector.

    // Dot product with a VectorValue
    let weightVector = VectorValue(vector: [0.5, -0.5])
    Field("features").dotProduct(weightVector)
    

    Default Implementation

    Declaration

    Swift

    func dotProduct(_ vector: VectorValue) -> FunctionExpression

    Parameters

    vector

    The other vector as a VectorValue to calculate with.

    Return Value

    A new FunctionExpression representing the dot product.

  • dotProduct(_:)

    Default implementation

    Calculates the dot product between this vector expression and another vector literal ([Double]). Assumes self evaluates to a Vector.

    // Dot product between a feature vector and a target vector literal
    Field("features").dotProduct([0.5, 0.8, 0.2])
    

    Default Implementation

    Declaration

    Swift

    func dotProduct(_ vector: [Double]) -> FunctionExpression

    Parameters

    vector

    The other vector as [Double] to calculate with.

    Return Value

    A new FunctionExpression representing the dot product.

  • euclideanDistance(_:)

    Default implementation

    Calculates the Euclidean distance between this vector expression and another vector expression. Assumes both self and other evaluate to Vectors.

    // Euclidean distance between "pointA" and "pointB" fields
    Field("pointA").euclideanDistance(Field("pointB"))
    

    Default Implementation

    Declaration

    Swift

    func euclideanDistance(_ expression: Expression) -> FunctionExpression

    Parameters

    expression

    The other vector as an Expr to compare against.

    Return Value

    A new FunctionExpression representing the Euclidean distance.

  • euclideanDistance(_:)

    Default implementation

    Calculates the Euclidean distance between this vector expression and another vector literal (VectorValue). Assumes self evaluates to a Vector.

    let targetPoint = VectorValue(vector: [1.0, 2.0])
    Field("currentLocation").euclideanDistance(targetPoint)
    

    Default Implementation

    Declaration

    Swift

    func euclideanDistance(_ vector: VectorValue) -> FunctionExpression

    Parameters

    vector

    The other vector as a VectorValue to compare against.

    Return Value

    A new FunctionExpression representing the Euclidean distance.

  • euclideanDistance(_:)

    Default implementation

    Calculates the Euclidean distance between this vector expression and another vector literal ([Double]). Assumes self evaluates to a Vector.

    // Euclidean distance between "location" field and a target location literal
    Field("location").euclideanDistance([37.7749, -122.4194])
    

    Default Implementation

    Declaration

    Swift

    func euclideanDistance(_ vector: [Double]) -> FunctionExpression

    Parameters

    vector

    The other vector as [Double] to compare against.

    Return Value

    A new FunctionExpression representing the Euclidean distance.

  • unixMicrosToTimestamp()

    Default implementation

    Creates an expression that interprets this expression (evaluating to a number) as microseconds since the Unix epoch and returns a timestamp. Assumes self evaluates to a number.

    // Interpret "microseconds" field as microseconds since epoch.
    Field("microseconds").unixMicrosToTimestamp()
    

    Default Implementation

    Declaration

    Swift

    func unixMicrosToTimestamp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the timestamp.

  • timestampToUnixMicros()

    Default implementation

    Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch. Assumes self evaluates to a Timestamp.

    // Convert "timestamp" field to microseconds since epoch.
    Field("timestamp").timestampToUnixMicros()
    

    Default Implementation

    Declaration

    Swift

    func timestampToUnixMicros() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the number of microseconds.

  • unixMillisToTimestamp()

    Default implementation

    Creates an expression that interprets this expression (evaluating to a number) as milliseconds since the Unix epoch and returns a timestamp. Assumes self evaluates to a number.

    // Interpret "milliseconds" field as milliseconds since epoch.
    Field("milliseconds").unixMillisToTimestamp()
    

    Default Implementation

    Declaration

    Swift

    func unixMillisToTimestamp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the timestamp.

  • timestampToUnixMillis()

    Default implementation

    Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch. Assumes self evaluates to a Timestamp.

    // Convert "timestamp" field to milliseconds since epoch.
    Field("timestamp").timestampToUnixMillis()
    

    Default Implementation

    Declaration

    Swift

    func timestampToUnixMillis() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the number of milliseconds.

  • unixSecondsToTimestamp()

    Default implementation

    Creates an expression that interprets this expression (evaluating to a number) as seconds since the Unix epoch and returns a timestamp. Assumes self evaluates to a number.

    // Interpret "seconds" field as seconds since epoch.
    Field("seconds").unixSecondsToTimestamp()
    

    Default Implementation

    Declaration

    Swift

    func unixSecondsToTimestamp() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the timestamp.

  • timestampToUnixSeconds()

    Default implementation

    Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch. Assumes self evaluates to a Timestamp.

    // Convert "timestamp" field to seconds since epoch.
    Field("timestamp").timestampToUnixSeconds()
    

    Default Implementation

    Declaration

    Swift

    func timestampToUnixSeconds() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the number of seconds.

  • timestampTruncate(granularity:)

    Default implementation

    Creates an expression that truncates a timestamp to a specified granularity. Assumes self evaluates to a Timestamp.

    // Truncate "timestamp" field to the nearest day.
    Field("timestamp").timestampTruncate(granularity: .day)
    

    Default Implementation

    Declaration

    Swift

    func timestampTruncate(granularity: TimeGranularity) -> FunctionExpression

    Parameters

    granularity

    A TimeGranularity representing the truncation unit.

    Return Value

    A new FunctionExpression representing the truncated timestamp.

  • timestampTruncate(granularity:)

    Default implementation

    Creates an expression that truncates a timestamp to a specified granularity. Assumes self evaluates to a Timestamp.

    // Truncate "timestamp" field to the nearest day using a literal string.
    Field("timestamp").timestampTruncate(granularity: "day")
    
    // Truncate "timestamp" field to the nearest day using an expression.
    Field("timestamp").timestampTruncate(granularity: Field("granularity_field"))
    

    Default Implementation

    Declaration

    Swift

    func timestampTruncate(granularity: Sendable) -> FunctionExpression

    Parameters

    granularity

    A Sendable literal string or an Expression that evaluates to a string, specifying the truncation unit.

    Return Value

    A new FunctionExpression representing the truncated timestamp.

  • Creates an expression that truncates a timestamp to a specified granularity with a specified timezone. Assumes self evaluates to a Timestamp.

    // Truncate "timestamp" field to the nearest day in Los Angeles timezone.
    Field("timestamp").timestampTruncate(granularity: .day, timezone: "America/Los_Angeles")
    

    Default Implementation

    Declaration

    Swift

    func timestampTruncate(granularity: TimeGranularity, timezone: Sendable) -> FunctionExpression

    Parameters

    granularity

    A TimeGranularity representing the truncation unit.

    timezone

    A Sendable literal string or an Expression representing the timezone.

    Return Value

    A new FunctionExpression representing the truncated timestamp.

  • Creates an expression that truncates a timestamp to a specified granularity with a specified timezone. Assumes self evaluates to a Timestamp.

    // Truncate "timestamp" field to the nearest day in Los Angeles timezone using a literal
    // string.
    Field("timestamp").timestampTruncate(granularity: "day", timezone: "America/Los_Angeles")
    
    // Truncate "timestamp" field to the granularity specified by "granularity_field" in the
    // timezone specified by "timezone_field" using expressions.
    Field("timestamp").timestampTruncate(
      granularity: Field("granularity_field"),
      timezone: Field("timezone_field")
    )
    

    Default Implementation

    Declaration

    Swift

    func timestampTruncate(granularity: Sendable, timezone: Sendable) -> FunctionExpression

    Parameters

    granularity

    A Sendable literal string or an Expression representing the truncation unit.

    timezone

    A Sendable literal string or an Expression representing the timezone.

    Return Value

    A new FunctionExpression representing the truncated timestamp.

  • timestampDiff(_:_:)

    Default implementation

    Calculates the difference between this timestamp and another timestamp.

    // Calculate the difference in days between "endAt" (self) and a start field using a typed
    // unit.
    Field("endAt").timestampDiff(Field("startAt"), .day)
    

    Default Implementation

    Declaration

    Swift

    func timestampDiff(_ start: Expression, _ unit: TimeUnit) -> FunctionExpression

    Parameters

    start

    An Expression representing the starting timestamp.

    unit

    A TimeUnit representing the unit of time for the difference.

    Return Value

    A new FunctionExpression representing the difference.

  • timestampDiff(_:_:)

    Default implementation

    Calculates the difference between this timestamp and another timestamp.

    // Calculate the difference in days between "endAt" (self) and a start field using a string
    // unit.
    Field("endAt").timestampDiff(Field("startAt"), "day")
    

    Default Implementation

    Declaration

    Swift

    func timestampDiff(_ start: Expression, _ unit: Sendable) -> FunctionExpression

    Parameters

    start

    An Expression representing the starting timestamp.

    unit

    A Sendable literal string or an Expression representing the unit of time.

    Return Value

    A new FunctionExpression representing the difference.

  • timestampExtract(part:)

    Default implementation

    Creates an expression that extracts a specified part from this timestamp expression.

    // Extract the day from the "timestamp" field.
    Field("timestamp").timestampExtract(part: .day)
    

    Default Implementation

    Declaration

    Swift

    func timestampExtract(part: TimePart) -> FunctionExpression

    Parameters

    part

    A TimePart representing the part to extract.

    Return Value

    A new FunctionExpression representing the extracted part.

  • timestampExtract(part:)

    Default implementation

    Creates an expression that extracts a specified part from this timestamp expression using a literal or expression.

    // Extract the day from the "timestamp" field using a string.
    Field("timestamp").timestampExtract(part: "day")
    

    Default Implementation

    Declaration

    Swift

    func timestampExtract(part: Sendable) -> FunctionExpression

    Parameters

    part

    A Sendable literal string or an Expression representing the part to extract.

    Return Value

    A new FunctionExpression representing the extracted part.

  • timestampExtract(part:timezone:)

    Default implementation

    Creates an expression that extracts a specified part from this timestamp expression in a given timezone.

    // Extract the day from the "timestamp" field in Los Angeles timezone.
    Field("timestamp").timestampExtract(part: .day, timezone: "America/Los_Angeles")
    

    Default Implementation

    Declaration

    Swift

    func timestampExtract(part: TimePart, timezone: Sendable) -> FunctionExpression

    Parameters

    part

    A TimePart representing the part to extract.

    timezone

    A Sendable literal string or an Expression representing the timezone.

    Return Value

    A new FunctionExpression representing the extracted part.

  • timestampExtract(part:timezone:)

    Default implementation

    Creates an expression that extracts a specified part from this timestamp expression in a given timezone using a literal or expression.

    // Extract the day from the "timestamp" field in Los Angeles timezone using a string.
    Field("timestamp").timestampExtract(part: "day", timezone: "America/Los_Angeles")
    

    Default Implementation

    Declaration

    Swift

    func timestampExtract(part: Sendable, timezone: Sendable) -> FunctionExpression

    Parameters

    part

    A Sendable literal string or an Expression representing the part to extract.

    timezone

    A Sendable literal string or an Expression representing the timezone.

    Return Value

    A new FunctionExpression representing the extracted part.

  • timestampAdd(_:_:)

    Default implementation

    Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as literals. Assumes self evaluates to a Timestamp.

    // Add 1 day to the "timestamp" field.
    Field("timestamp").timestampAdd(1, .day)
    

    Default Implementation

    Declaration

    Swift

    func timestampAdd(_ amount: Int, _ unit: TimeUnit) -> FunctionExpression

    Parameters

    unit

    The TimeUnit enum representing the unit of time.

    amount

    The literal Int amount of the unit to add.

    Return Value

    A new "FunctionExpression" representing the resulting timestamp.

  • timestampAdd(amount:unit:)

    Default implementation

    Creates an expression that adds a specified amount of time to this timestamp expression, where unit and amount are provided as an expression for amount and a literal for unit. Assumes self evaluates to a Timestamp, amount evaluates to an integer, and unit evaluates to a string.

    // Add duration from "amountField" to "timestamp" with a literal unit "day".
    Field("timestamp").timestampAdd(amount: Field("amountField"), unit: "day")
    

    Default Implementation

    Declaration

    Swift

    func timestampAdd(amount: Expression, unit: Sendable) -> FunctionExpression

    Parameters

    unit

    A Sendable literal string specifying the unit of time. Valid units are "microsecond", "millisecond", "second", "minute", "hour", "day".

    amount

    An Expression evaluating to the amount (Int) of the unit to add.

    Return Value

    A new "FunctionExpression" representing the resulting timestamp.

  • timestampSubtract(_:_:)

    Default implementation

    Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as literals. Assumes self evaluates to a Timestamp.

    // Subtract 1 day from the "timestamp" field.
    Field("timestamp").timestampSubtract(1, .day)
    

    Default Implementation

    Declaration

    Swift

    func timestampSubtract(_ amount: Int, _ unit: TimeUnit) -> FunctionExpression

    Parameters

    unit

    The TimeUnit enum representing the unit of time.

    amount

    The literal Int amount of the unit to subtract.

    Return Value

    A new "FunctionExpression" representing the resulting timestamp.

  • timestampSubtract(amount:unit:)

    Default implementation

    Creates an expression that subtracts a specified amount of time from this timestamp expression, where unit and amount are provided as an expression for amount and a literal for unit. Assumes self evaluates to a Timestamp, amount evaluates to an integer, and unit evaluates to a string.

    // Subtract duration from "amountField" from "timestamp" with a literal unit "day".
    Field("timestamp").timestampSubtract(amount: Field("amountField"), unit: "day")
    

    Default Implementation

    Declaration

    Swift

    func timestampSubtract(amount: Expression, unit: Sendable) -> FunctionExpression

    Parameters

    unit

    A Sendable literal string specifying the unit of time. Valid units are "microsecond", "millisecond", "second", "minute", "hour", "day".

    amount

    An Expression evaluating to the amount (Int) of the unit to subtract.

    Return Value

    A new "FunctionExpression" representing the resulting timestamp.

  • documentId()

    Default implementation

    Creates an expression that returns the document ID from a path.

    // Get the document ID from a path.
    Field(FieldPath.documentID()).documentId()
    

    Default Implementation

    Declaration

    Swift

    func documentId() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the documentId operation.

  • collectionId()

    Default implementation

    Gets the collection id (kind) of a given document (either an absolute or namespace relative reference). Throw error if the input is the root itself.

    Default Implementation

    Declaration

    Swift

    func collectionId() -> FunctionExpression
  • parent()

    Default implementation

    Creates an expression that returns the parent document reference of a document reference.

    // Get the parent document reference of a document reference.
    Field("__path__").parent()
    

    Default Implementation

    Declaration

    Swift

    func parent() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the parent operation.

  • ifError(_:)

    Default implementation

    Creates an expression that returns the result of catchExpression if this expression produces an error during evaluation, otherwise returns the result of this expression.

    // Try dividing "a" by "b", return field "fallbackValue" on error (e.g., division by zero)
    Field("a").divide(Field("b")).ifError(Field("fallbackValue"))
    

    Default Implementation

    Declaration

    Swift

    func ifError(_ catchExpression: Expression) -> FunctionExpression

    Parameters

    catchExpression

    The Expression to evaluate and return if this expression errors.

    Return Value

    A new "FunctionExpression" representing the "ifError" operation.

  • ifError(_:)

    Default implementation

    Creates an expression that returns the literal catchValue if this expression produces an error during evaluation, otherwise returns the result of this expression.

    // Get first item in "title" array, or return "Default Title" if error (e.g., empty array)
    Field("title").arrayGet(0).ifError("Default Title")
    

    Default Implementation

    Declaration

    Swift

    func ifError(_ catchValue: Sendable) -> FunctionExpression

    Parameters

    catchValue

    The literal Sendable value to return if this expression errors.

    Return Value

    A new "FunctionExpression" representing the "ifError" operation.

  • ifAbsent(_:)

    Default implementation

    Creates an expression that returns the literal defaultValue if this expression is absent (e.g., a field does not exist in a map). Otherwise, returns the result of this expression.

    // If the "optionalField" is absent, return "default value".
    Field("optionalField").ifAbsent("default value")
    

    Default Implementation

    Declaration

    Swift

    func ifAbsent(_ defaultValue: Sendable) -> FunctionExpression

    Parameters

    defaultValue

    The literal Sendable value to return if this expression is absent.

    Return Value

    A new "FunctionExpression" representing the "ifAbsent" operation.

  • ifNull(_:)

    Default implementation

    Creates an expression that returns the else argument if this expression evaluates to null, else return the result of this expression.

    This function provides a fallback for both absent and explicit null values. In contrast, ifAbsent only triggers for missing fields.

    // Returns the user's display name, or returns "Anonymous" if the field is null.
    Field("displayName").ifNull("Anonymous")
    

    Default Implementation

    Declaration

    Swift

    func ifNull(_ defaultValue: Sendable) -> FunctionExpression

    Parameters

    defaultValue

    The Sendable value that will be returned if this expression evaluates to null.

    Return Value

    A new FunctionExpression representing the ifNull operation.

  • ifNull(_:)

    Default implementation

    Creates an expression that returns the else argument if this expression evaluates to null, else return the result of this expression.

    This function provides a fallback for both absent and explicit null values. In contrast, ifAbsent only triggers for missing fields.

    // Returns the user's preferred name, or if that is null, returns their full name.
    Field("preferredName").ifNull(Field("fullName"))
    

    Default Implementation

    Declaration

    Swift

    func ifNull(_ defaultExpression: Expression) -> FunctionExpression

    Parameters

    defaultExpression

    The Expression that will be evaluated and returned if this expression evaluates to null.

    Return Value

    A new FunctionExpression representing the ifNull operation.

  • coalesce(_:)

    Default implementation

    Creates an expression that returns the first non-null, non-absent argument, without evaluating the rest of the arguments. When all arguments are null or absent, returns the last argument.

    // Returns the value of the first non-null, non-absent field among 'preferredName',
    'fullName', or the last argument if all previous fields are null.
    Field("preferredName").coalesce([Field("fullName"), Constant("Anonymous")])
    

    Default Implementation

    Declaration

    Swift

    func coalesce(_ values: [Expression]) -> FunctionExpression

    Parameters

    values

    Optional additional expressions to check if previous ones are null.

    Return Value

    A new FunctionExpression representing the coalesce operation.

  • ascending()

    Default implementation

    Creates an Ordering object that sorts documents in ascending order based on this expression.

    // Sort documents by the "name" field in ascending order
    firestore.pipeline().collection("users")
      .sort(Field("name").ascending())
    

    Default Implementation

    Declaration

    Swift

    func ascending() -> Ordering

    Return Value

    A new Ordering instance for ascending sorting.

  • descending()

    Default implementation

    Creates an Ordering object that sorts documents in descending order based on this expression.

    // Sort documents by the "createdAt" field in descending order
    firestore.pipeline().collection("users")
      .sort(Field("createdAt").descending())
    

    Default Implementation

    Declaration

    Swift

    func descending() -> Ordering

    Return Value

    A new Ordering instance for descending sorting.

  • concat(_:)

    Default implementation

    Creates an expression that concatenates multiple sequenceable types together.

    // Concatenate the firstName and lastName with a space in between.
    Field("firstName").concat([" ", Field("lastName")])
    

    Default Implementation

    Declaration

    Swift

    func concat(_ values: [Sendable]) -> FunctionExpression

    Parameters

    values

    The values to concatenate.

    Return Value

    A new FunctionExpression representing the concatenated result.

  • type()

    Default implementation

    Creates an expression that returns the type of the expression.

    // Get the type of the "rating" field.
    Field("rating").type()
    

    Default Implementation

    Declaration

    Swift

    func type() -> FunctionExpression

    Return Value

    A new FunctionExpression representing the type of the expression as a string.

  • isType(_:)

    Default implementation

    Creates an expression that checks if the result of this expression is of the given type.

    Supported values for type are: "null", "array", "boolean", "bytes", "timestamp", "geo_point", "number", "int32", "int64", "float64", "decimal128", "map", "reference", "string", "vector", "max_key", "min_key", "object_id", "regex", and "request_timestamp".

    // Check if the "age" field is an integer
    Field("age").isType("int64")
    

    Default Implementation

    Declaration

    Swift

    func isType(_ type: String) -> BooleanExpression

    Parameters

    type

    The type to check for.

    Return Value

    A new BooleanExpression that evaluates to true if the expression's result is of the given type, false otherwise.