Sequence

extension Sequence
extension Sequence where Element == SQLLiteral
extension Sequence where Element == SQLExpression
extension Sequence where Self.Iterator.Element: SQLExpressible
  • Returns a cursor over the concatenated results of mapping transform over self.

    Declaration

    Swift

    public func flatMap<SegmentOfResult: Cursor>(
        _ transform: @escaping (Iterator.Element) throws -> SegmentOfResult)
        -> FlattenCursor<MapCursor<AnyCursor<Iterator.Element>, SegmentOfResult>>

Available where Element == SQLLiteral

  • Returns the concatenated SQLLiteral of this sequence of literals, inserting the given separator between each element.

    let components: [SQLLiteral] = [
        "UPDATE player",
        "SET name = \(name)",
        "WHERE id = \(id)"
    ]
    let query = components.joined(separator: " ")
    

    Declaration

    Swift

    public func joined(separator: String = "") -> SQLLiteral

Available where Element == SQLExpression

  • Returns an expression by joining all elements with an SQL binary operator.

    For example:

    // SELECT * FROM player
    // WHERE (registered
    //        AND (score >= 1000)
    //        AND (name IS NOT NULL))
    let conditions = [
        Column("registered"),
        Column("score") >= 1000,
        Column("name") != nil]
    Player.filter(conditions.joined(operator: .and))
    

    When the sequence is empty, joined(operator:) returns the neutral value of the operator. It is 0 (zero) for .add, 1 for ‘.multiply, false for.or, true for.and... andjoined(operator: .or)returns false: When the sequence is empty,joined(operator: .and)returns true, andjoined(operator: .or)` returns false:

    // SELECT 0 FROM player
    Player.select([].joined(operator: .add))
    
    // SELECT * FROM player WHERE 1
    Player.filter([].joined(operator: .and))
    
    // SELECT * FROM player WHERE 0
    Player.filter([].joined(operator: .or))
    

    Declaration

    Swift

    public func joined(operator: SQLAssociativeBinaryOperator) -> SQLExpression

Available where Self.Iterator.Element: SQLExpressible

  • An SQL expression that checks the inclusion of an expression in a sequence.

    // id IN (1,2,3)
    [1, 2, 3].contains(Column("id"))
    

    Declaration

    Swift

    public func contains(_ element: SQLSpecificExpressible) -> SQLExpression
  • An SQL expression that checks the inclusion of an expression in a sequence.

    // name IN ('A', 'B') COLLATE NOCASE
    ["A", "B"].contains(Column("name").collating(.nocase))
    

    Declaration

    Swift

    public func contains(_ element: SQLCollatedExpression) -> SQLExpression