SQLPredicateBuilder

public protocol SQLPredicateBuilder : AnyObject

Builds SQLExpression predicates, i.e., WHERE clauses.

builder.where(\Planet.name == "Earth")

Expressions will be added using AND logic by default. Use orWhere to join via OR logic.

builder.where(\Planet.name == "Earth").orWhere(\Planet.name == "Mars")

See SQLPredicateGroupBuilder for building expression groups.

  • where(_:) Extension method

    Adds an expression to the WHERE clause.

    builder.where(\Planet.name == "Earth")
    

    Declaration

    Swift

    public func `where`(_ expression: Expression) -> Self

    Parameters

    expression

    Expression to be added via AND to the predicate.

  • orWhere(_:) Extension method

    Adds an expression to the WHERE clause.

    builder.orWhere(\Planet.name == "Earth")
    

    Declaration

    Swift

    public func orWhere(_ expression: Expression) -> Self

    Parameters

    expression

    Expression to be added via OR to the predicate.

  • where(_:_:_:) Extension method

    Adds an expression to the WHERE clause.

    builder.where(.column("name"), .equal, .value("Earth"))
    

    Declaration

    Swift

    public func `where`(_ lhs: Expression, _ op: Expression.BinaryOperator, _ rhs: Expression) -> Self
  • orWhere(_:_:_:) Extension method

    Adds an expression to the WHERE clause.

    builder.orWhere(.column("name"), .equal, .value("Earth"))
    

    Declaration

    Swift

    public func orWhere(_ lhs: Expression, _ op: Expression.BinaryOperator, _ rhs: Expression) -> Self
  • where(group:) Extension method

    Builds a grouped WHERE expression.

    builder.where(\Planet.type == .smallRocky).where {
        $0.where(\Planet.name == "Earth").orWhere(\Planet.name == "Mars")
    }
    

    The above code would result in the following SQL.

    WHERE "type" = "smallRocky" AND ("name" = "Earth" OR "name" = "Mars")
    

    Declaration

    Swift

    public func `where`(group: (SQLPredicateGroupBuilder<Self>) throws -> ()) rethrows -> Self
  • orWhere(group:) Extension method

    Builds a grouped WHERE expression.

    builder.where(\Planet.name == "Jupiter").orWhere {
        $0.where(\Planet.name == "Earth").where(\Planet.type == .smallRocky)
    }
    

    The above code would result in the following SQL.

    WHERE "name" = "Jupiter" OR ("name" = "Earth" AND "type" = "smallRocky")
    

    Declaration

    Swift

    public func orWhere(group: (SQLPredicateGroupBuilder<Self>) throws -> ()) rethrows -> Self