Insert

public struct Insert : Query

The SQL INSERT statement.

  • The table to insert rows.

    Declaration

    Swift

    public let table: Table
  • An array of columns to insert. If not specified, values of all the columns have to be provided.

    Declaration

    Swift

    public let columns: [Column]?
  • An array of rows (values to insert in each row).

    Declaration

    Swift

    public private(set) var values: [[Any]]? { get }
  • A String with a clause to be appended to the end of the query.

    Declaration

    Swift

    public private(set) var suffix: QuerySuffixProtocol? { get }
  • The select query that retrieves the rows to insert (for INSERT INTO SELECT).

    Declaration

    Swift

    public private(set) var query: Select? { 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 }
  • A flag for return ID

    Declaration

    Swift

    public let returnID: Bool
  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, columns: [Column]?, values: [Any], returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    columns

    An optional array of columns to insert. If nil, values of all the columns have to be provided.

    values

    An array containg the row to insert.

  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, columns: [Column]? = nil, rows: [[Any]], returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    columns

    An optional array of columns to insert. If not specified, values of all the columns have to be provided.

    values

    An array of rows (values to insert in each row).

  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, values: Any..., returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    values

    A list of values (the row) to insert.

  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, values: [Any], returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    values

    An array of values (the row) to insert.

  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, valueTuples: [(Column, Any)], returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    valueTuples

    An array of (column, value) pairs to insert.

  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, valueTuples: (Column, Any)..., returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    valueTuples

    A list of (column, value) pairs to insert.

  • Initialize an instance of Insert.

    Declaration

    Swift

    public init(into table: Table, columns: [Column]? = nil, _ query: Select, returnID: Bool = false)

    Parameters

    into

    The table to insert rows.

    columns

    An optional array of columns to insert. If nil, values of all the columns have to be provided.

    query

    The select query that retrieves the rows to insert.

  • 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.

  • Add a raw suffix to the insert statement.

    Declaration

    Swift

    public func suffix(_ raw: String) -> Insert

    Parameters

    raw

    A String with a clause to be appended to the end of the query.

    Return Value

    A new instance of Insert.