Select

public struct Select : Query

The SQL SELECT statement.

  • An array of Field elements to select.

    Declaration

    Swift

    public let fields: [Field]?
  • The table to select rows from.

    Declaration

    Swift

    public let tables: [Table]
  • The SQL WHERE clause containing the filter for rows to retrieve. Could be represented with a Filter clause or a String containing raw SQL.

    Declaration

    Swift

    public private(set) var whereClause: QueryFilterProtocol? { get }
  • A boolean indicating whether the selected values have to be distinct. If true, corresponds to the SQL SELECT DISTINCT statement.

    Declaration

    Swift

    public private(set) var distinct: Bool { get }
  • The number of rows to select. If specified, corresponds to the SQL SELECT TOP/LIMIT clause.

    Declaration

    Swift

    public private(set) var rowsToReturn: Int? { get }
  • The number of rows to skip. If specified, corresponds to the SQL SELECT OFFSET clause.

    Declaration

    Swift

    public private(set) var offset: Int? { get }
  • An array containing OrderBy elements to sort the selected rows. The SQL ORDER BY keyword.

    Declaration

    Swift

    public private(set) var orderBy: [OrderBy]? { get }
  • An array containing Column elements to group the selected rows. The SQL GROUP BY statement.

    Declaration

    Swift

    public private(set) var groupBy: [Column]? { get }
  • The SQL HAVING clause containing the filter for the rows to select when aggregate functions are used. Could be represented with a Having clause or a String containing raw SQL.

    Declaration

    Swift

    public private(set) var havingClause: QueryHavingProtocol? { get }
  • The SQL UNION clauses.

    Declaration

    Swift

    public private(set) var unions: [Union]? { get }
  • The SQL JOIN, ON and USING clauses. ON clause can be represented as Filter or a String containing raw SQL. USING clause: an array of Column elements that have to match in a JOIN query.

    Declaration

    Swift

    public private(set) var joins: [(join: Join, on: QueryFilterProtocol?, using: [Column]?)] { get }
  • An array of AuxiliaryTable which will be used in a query with a WITH clause.

    Declaration

    Swift

    public private(set) var with: [AuxiliaryTable]? { get }
  • Initialize an instance of Select.

    Declaration

    Swift

    public init(_ fields: Field..., from table: Table)

    Parameters

    fields

    A list of Field elements to select.

  • Initialize an instance of Select.

    Declaration

    Swift

    public init(_ fields: [Field], from table: Table...)

    Parameters

    fields

    An array of Field elements to select.

  • Initialize an instance of Select.

    Declaration

    Swift

    public init(_ fields: Field..., from tables: [Table])

    Parameters

    fields

    A list of Field elements to select.

  • Initialize an instance of Select.

    Declaration

    Swift

    public init(fields: [Field], from tables: [Table])

    Parameters

    fields

    An array of Field elements to select.

  • Build the query using QueryBuilder.

    Throws

    QueryError.syntaxError if query build fails.

    Declaration

    Swift

    public func build(queryBuilder: QueryBuilder) throws -> String

    Parameters

    queryBuilder

    The QueryBuilder to use.

    Return Value

    A String representation of the query.

  • Create a SELECT DISTINCT query.

    Declaration

    Swift

    public static func distinct(_ fields: Field..., from table: Table) -> Select

    Parameters

    fields

    A list of Fields to select.

    from

    The table to select from.

    Return Value

    A new instance of Select with distinct flag set.

  • Create a SELECT DISTINCT query.

    Declaration

    Swift

    public static func distinct(_ fields: [Field], from table: Table...) -> Select

    Parameters

    fields

    An array of Fields to select.

    Return Value

    A new instance of Select with distinct flag set.

  • Create a SELECT DISTINCT query.

    Declaration

    Swift

    public static func distinct(_ fields: Field..., from tables: [Table]) -> Select

    Parameters

    fields

    A list of Fields to select.

    from

    An array of tables to select from.

    Return Value

    A new instance of Select with distinct flag set.

  • Create a SELECT DISTINCT query.

    Declaration

    Swift

    public static func distinct(fields: [Field], from tables: [Table]) -> Select

    Parameters

    fields

    An array of Fields to select.

    from

    An array of tables to select from.

    Return Value

    A new instance of Select with distinct flag set.

  • Add the HAVING clause to the query.

    Declaration

    Swift

    public func having(_ clause: QueryHavingProtocol) -> Select

    Parameters

    clause

    The Having clause or a String containing SQL HAVING clause to apply.

    Return Value

    A new instance of Select with the Having clause.

  • Add the ORDER BY keyword to the query.

    Declaration

    Swift

    public func order(by clause: OrderBy...) -> Select

    Parameters

    by

    A list of the OrderBy to apply.

    Return Value

    A new instance of Select with the ORDER BY keyword.

  • Add the ORDER BY keyword to the query.

    Declaration

    Swift

    public func order(by clause: [OrderBy]) -> Select

    Parameters

    by

    An array of the OrderBy to apply.

    Return Value

    A new instance of Select with the ORDER BY keyword.

  • Add the GROUP BY clause to the query.

    Declaration

    Swift

    public func group(by clause: Column...) -> Select

    Parameters

    by

    A list of Columns to group by.

    Return Value

    A new instance of Select with the GROUP BY clause.

  • Add the GROUP BY clause to the query.

    Declaration

    Swift

    public func group(by clause: [Column]) -> Select

    Parameters

    by

    A list of Columns to group by.

    Return Value

    A new instance of Select with the GROUP BY clause.

  • Add the LIMIT/TOP clause to the query.

    Declaration

    Swift

    public func limit(to newLimit: Int) -> Select

    Parameters

    to

    The limit of the number of rows to select.

    Return Value

    A new instance of Select with the LIMIT clause.

  • Add the OFFSET clause to the query.

    Declaration

    Swift

    public func offset(_ offset: Int) -> Select

    Parameters

    to

    The number of rows to skip.

    Return Value

    A new instance of Select with the OFFSET clause.

  • Add an SQL WHERE clause to the select statement.

    Declaration

    Swift

    public func `where`(_ conditions: QueryFilterProtocol) -> Select

    Parameters

    conditions

    The Filter clause or a String containing SQL WHERE clause to apply.

    Return Value

    A new instance of Select with the WHERE clause.

  • Add an SQL ON clause to the JOIN statement.

    Declaration

    Swift

    public func on(_ conditions: QueryFilterProtocol) -> Select

    Parameters

    conditions

    The Filter clause or a String containing SQL ON clause to apply.

    Return Value

    A new instance of Select with the ON clause.

  • Add an SQL USING clause to the JOIN statement.

    Declaration

    Swift

    public func using(_ columns: Column...) -> Select

    Parameters

    columns

    A list of Columns to match in the JOIN statement.

    Return Value

    A new instance of Select with the USING clause.

  • Add an SQL USING clause to the JOIN statement.

    Declaration

    Swift

    public func using(_ columns: [Column]) -> Select

    Parameters

    columns

    An array of Columns to match in the JOIN statement.

    Return Value

    A new instance of Select with the USING clause.

  • Create an SQL SELECT UNION statement.

    Declaration

    Swift

    public func union(_ query: Select) -> Select

    Parameters

    table

    The second Select query used in performing the union.

    Return Value

    A new instance of Select corresponding to the SELECT UNION.

  • Create an SQL SELECT UNION ALL statement.

    Declaration

    Swift

    public func unionAll(_ query: Select) -> Select

    Parameters

    table

    The second Select query used in performing the union.

    Return Value

    A new instance of Select corresponding to the SELECT UNION ALL.

  • Create an SQL SELECT INNER JOIN statement.

    Declaration

    Swift

    public func join(_ table: Table) -> Select

    Parameters

    table

    The right table used in performing the join. The left table is the table field of this Select instance.

    Return Value

    A new instance of Select corresponding to the SELECT INNER JOIN.

  • Create an SQL SELECT LEFT JOIN statement.

    Declaration

    Swift

    public func leftJoin(_ table: Table) -> Select

    Parameters

    table

    The right table used in performing the join. The left table is the table field of this Select instance.

    Return Value

    A new instance of Select corresponding to the SELECT LEFT JOIN.

  • Create an SQL SELECT CROSS JOIN statement.

    Declaration

    Swift

    public func crossJoin(_ table: Table) -> Select

    Parameters

    table

    The right table used in performing the join. The left table is the table field of this Select instance.

    Return Value

    A new instance of Select corresponding to the SELECT CROSS JOIN.

  • Create an SQL SELECT NATURAL JOIN statement.

    Declaration

    Swift

    public func naturalJoin(_ table: Table) -> Select

    Parameters

    table

    The right table used in performing the join. The left table is the table field of this Select instance.

    Return Value

    A new instance of Select corresponding to the SELECT NATURAL JOIN.

  • Create a join statement with the type of join specified in the String.

    Declaration

    Swift

    public func rawJoin(_ raw: String, _ table: Table) -> Select

    Parameters

    raw

    A String containg a join to apply.

    table

    The right table used in performing the join. The left table is the table field of this Select instance.

    Return Value

    A new instance of Select corresponding to the join.