-
Notifications
You must be signed in to change notification settings - Fork 43
More flexible insert builder #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| @attached( | ||
| extension, | ||
| conformances: QueryRepresentable, | ||
| conformances: Selection, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Selection now has its own conformance so that we can write generic algorithms against them. This is what allows them to be passed to Table.insert.
| or conflictResolution: ConflictResolution? = nil, | ||
| _ columns: (TableColumns) -> TableColumns = { $0 }, | ||
| @InsertValuesBuilder<Self> values: () -> [Self], | ||
| @InsertValuesBuilder<Self> values: () -> [[QueryFragment]], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The @InsertValuesBuilder is now responsible for building up an array of query fragments to insert.
| /// | ||
| /// - Parameter build: A result builder closure that prepares statements to insert every built row. | ||
| public init(@InsertValuesBuilder<any Table> _ build: () -> [any Table]) { | ||
| public init(@SeedsBuilder _ build: () -> [any Table]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main gotcha in this PR is that we need a simultaneous release with SharingGRDB since it defines a seeds helper that will be incompatible with this feature.
| ) | ||
| } | ||
|
|
||
| private static func _insert<each ConflictTarget>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of these overloads can be removed as the logic was moved into the result builder.
* Full-text search * wip * wip * Update FTS5.swift * wip * wip * wip * Make inserts more flexible * wip * wip * wip * wip * wip * wip * fix * wip
* Full-text search * wip * wip * Update FTS5.swift * wip * wip * wip * Make inserts more flexible * wip * wip * wip * wip * wip * wip * fix * wip
The result builder powering
Table.insertcurrently expects the same type of value for each row inserted, which means they all need to beTablevalues, or they all need to beTable.Draftvalues, or they all need to be tuples of bindable values.This PR adds a bit more flexibility to the builder so that different values can be inserted at the same time so long as they encode into the same set of values.
For example, table values can be inserted along drafts:
And Swift values can be inserted alongside SQL:
The PR also allows column expressions from applying
@Table @Selectionto be inserted: