Class
SQLInsertBuilder
Builds
SQLInsert queries.final class SQLInsertBuilder
Overview
Note
Although in the strictest sense, this builder could conform to SQLUnqualifiedColumnListBuilder, doing so would be semantically inappropriate. The protocol documents its columns() methods as being additive, but SQLInsertBuilder’s otherwise-identical public APIs overwrite the effects of any previous invocation. It would ideally be preferable to change SQLInsertBuilder‘s semantics in this regard, but this would be a significant breaking change in the API’s behavior, and must therefore wait for a major version bump.
Topics
Initializers
init(SQLInsert, on: any SQLDatabase)Creates a newSQLInsertBuilder.
Instance Properties
var database: any SQLDatabaseConnection to execute query on.var insert: SQLInsertTheSQLInsertquery this builder builds.var query: any SQLExpressionQuery being built.var returning: SQLReturning?The specification of what the query should return, if any.var tableExpressionGroup: SQLCommonTableExpressionGroup?An optional group of common table expressions to include in the query under construction.
Instance Methods
func columns(_:)Specify mutiple columns to be included in the list of columns for the query.func ignoringConflicts(with:)Specify that constraint violations for the key over the given column should cause the conflicting row(s) to be ignored.func model(some Encodable, prefix: String?, keyEncodingStrategy: SQLQueryEncoder.KeyEncodingStrategy, nilEncodingStrategy: SQLQueryEncoder.NilEncodingStrategy, userInfo: [CodingUserInfoKey : any Sendable]) throws -> SelfUse anEncodablevalue to generate a row to insert and add that row to the query.func model(some Encodable, with: SQLQueryEncoder) throws -> SelfUse anEncodablevalue to generate a row to insert and add that row to the query.func models([some Encodable], prefix: String?, keyEncodingStrategy: SQLQueryEncoder.KeyEncodingStrategy, nilEncodingStrategy: SQLQueryEncoder.NilEncodingStrategy, userInfo: [CodingUserInfoKey : any Sendable]) throws -> SelfUse an array ofEncodablevalues to generate rows to insert and add those rows to the query.func models([some Encodable], with: SQLQueryEncoder) throws -> SelfUse an array ofEncodablevalues to generate rows to insert and add those rows to the query.func onConflict(with:do:)Specify that constraint violations for the key over the given column should cause the conflicting row(s) to be updated as specified instead. SeeSQLConflictUpdateBuilder.func rows<S1, S2>(S1) -> SelfAdd multiple sequences of values each inserted as a separate row.func select((SQLSubqueryBuilder) throws -> SQLSubqueryBuilder) rethrows -> SelfSpecify aSELECTquery to generate rows to insert.func values(_:)Add a set of values to be inserted as a single row.
Relationships
Conforms To
See Also
Query Builders
class SQLAlterEnumBuilderBuildsSQLAlterEnumqueries.class SQLAlterTableBuilderBuildsSQLAlterTablequeries.class SQLConflictUpdateBuilderA builder for specifying column updates and an optional predicate to be applied to rows that caused unique key conflicts during anINSERT.class SQLCreateEnumBuilderBuildsSQLCreateEnumqueries.class SQLCreateIndexBuilderBuildsSQLCreateIndexqueries.class SQLCreateTableBuilderBuildsSQLCreateTablequeries.class SQLCreateTriggerBuilderBuildsSQLCreateTriggerqueries.class SQLDeleteBuilderBuildsSQLDeletequeries.class SQLDropEnumBuilderBuildsSQLDropEnumqueries.class SQLDropIndexBuilderBuildsSQLDropIndexqueries.class SQLDropTableBuilderBuildsSQLDropTablequeries.class SQLDropTriggerBuilderBuildsSQLDropTriggerqueries.class SQLPredicateGroupBuilderNestedSQLPredicateBuilderfor building expression groups.class SQLRawBuilderBuilds raw SQL queries.class SQLReturningResultBuilderA builder returned from the methods ofSQLReturningBuilder; this builder wraps the original builder with one which providesSQLQueryFetcherconformance. As such, thereturning(_:)methods must always be the last ones in any call chain.