Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/StructuredQueries/Macros.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public macro Ephemeral() =
/// or common table expression.
@attached(
extension,
conformances: QueryRepresentable,
conformances: _Selection,
names: named(Columns),
named(init(decoder:))
)
Expand Down
6 changes: 3 additions & 3 deletions Sources/StructuredQueriesCore/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension Table {
public static func insert(
or conflictResolution: ConflictResolution? = nil,
_ columns: (TableColumns) -> TableColumns = { $0 },
@InsertValuesBuilder<Self> values: () -> [Self],
@InsertValuesBuilder<Self> values: () -> [[QueryFragment]],
Copy link
Member Author

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.

onConflict updates: ((inout Updates<Self>) -> Void)?
) -> InsertOf<Self> {
insert(or: conflictResolution, columns, values: values, onConflictDoUpdate: updates)
Expand All @@ -75,8 +75,8 @@ extension Table {
public static func insert<V1, each V2>(
or conflictResolution: ConflictResolution? = nil,
_ columns: (TableColumns) -> (TableColumn<Self, V1>, repeat TableColumn<Self, each V2>),
@InsertValuesBuilder<(V1.QueryOutput, repeat (each V2).QueryOutput)>
values: () -> [(V1.QueryOutput, repeat (each V2).QueryOutput)],
@InsertValuesBuilder<(V1, repeat each V2)>
values: () -> [[QueryFragment]],
onConflict updates: ((inout Updates<Self>) -> Void)?
) -> InsertOf<Self> {
insert(or: conflictResolution, columns, values: values, onConflictDoUpdate: updates)
Expand Down
45 changes: 44 additions & 1 deletion Sources/StructuredQueriesCore/Seeds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public struct Seeds: Sequence {
/// [SharingGRDB]: https://github.com/pointfreeco/sharing-grdb
///
/// - 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]) {
Copy link
Member Author

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.

self.seeds = build()
}

Expand Down Expand Up @@ -103,3 +103,46 @@ public struct Seeds: Sequence {
}
}
}

@resultBuilder
public enum SeedsBuilder {
public static func buildArray(_ components: [[any Table]]) -> [any Table] {
components.flatMap(\.self)
}

public static func buildBlock(_ components: [any Table]) -> [any Table] {
components
}

public static func buildEither(first component: [any Table]) -> [any Table] {
component
}

public static func buildEither(second component: [any Table]) -> [any Table] {
component
}

public static func buildExpression(_ expression: some Table) -> [any Table] {
[expression]
}

public static func buildExpression(_ expression: [any Table]) -> [any Table] {
expression
}

public static func buildLimitedAvailability(_ component: [any Table]) -> [any Table] {
component
}

public static func buildOptional(_ component: [any Table]?) -> [any Table] {
component ?? []
}

public static func buildPartialBlock(first: [any Table]) -> [any Table] {
first
}

public static func buildPartialBlock(accumulated: [any Table], next: [any Table]) -> [any Table] {
accumulated + next
}
}
Loading