Skip to content

Commit 83e4d57

Browse files
author
Rob Amos
committed
Wrap optional functionality in traits.
1 parent 278b5e2 commit 83e4d57

File tree

11 files changed

+439
-313
lines changed

11 files changed

+439
-313
lines changed

Package.resolved

Lines changed: 8 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 79 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,48 @@ let package = Package(
3838
name: "StructuredQueriesTagged",
3939
description: "Introduce StructuredQueries conformances to the swift-tagged package.",
4040
enabledTraits: []
41-
)
41+
),
42+
.trait(
43+
name: "StructuredQueriesCustomDump",
44+
description: "Include swift-custom-dump support.",
45+
enabledTraits: []
46+
),
47+
.trait(
48+
name: "StructuredQueriesDependencies",
49+
description: "Include swift-dependencies support.",
50+
enabledTraits: []
51+
),
52+
.trait(
53+
name: "StructuredQueriesMacroTesting",
54+
description:
55+
"Include swift-macro-testing support. Generally only needed when running unit tests.",
56+
enabledTraits: []
57+
),
58+
.trait(
59+
name: "StructuredQueriesSnapshotTesting",
60+
description:
61+
"Include swift-snapshot-testing support. Generally only needed when running unit tests.",
62+
enabledTraits: []
63+
),
64+
.trait(
65+
name: "StructuredQueriesIssueReporting",
66+
description: "Include swift-issue-reporting (nee xctest-dynamic-overlay) support.",
67+
enabledTraits: []
68+
),
4269
],
4370
dependencies: [
4471
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.3.3"),
4572
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.8.1"),
46-
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.6.3"),
47-
.package(url: "https://github.com/pointfreeco/swift-snapshot-testing", from: "1.18.4"),
73+
.package(url: "https://github.com/bok-/swift-macro-testing-with-traits", from: "0.6.4+traits"),
74+
.package(
75+
url: "https://github.com/bok-/swift-snapshot-testing-with-traits",
76+
exact: "1.18.7+traits",
77+
traits: [
78+
.trait(
79+
name: "SnapshotTestingCustomDump",
80+
condition: .when(traits: ["StructuredQueriesCustomDump"]))
81+
]
82+
),
4883
.package(url: "https://github.com/pointfreeco/swift-tagged", from: "0.10.0"),
4984
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.5.2"),
5085
.package(url: "https://github.com/swiftlang/swift-syntax", "600.0.0"..<"603.0.0"),
@@ -60,7 +95,11 @@ let package = Package(
6095
.target(
6196
name: "StructuredQueriesCore",
6297
dependencies: [
63-
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
98+
.product(
99+
name: "IssueReporting",
100+
package: "xctest-dynamic-overlay",
101+
condition: .when(traits: ["StructuredQueriesIssueReporting"])
102+
),
64103
.product(
65104
name: "Tagged",
66105
package: "swift-tagged",
@@ -89,8 +128,7 @@ let package = Package(
89128
.target(
90129
name: "StructuredQueriesSQLiteCore",
91130
dependencies: [
92-
"StructuredQueriesCore",
93-
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
131+
"StructuredQueriesCore"
94132
]
95133
),
96134
.macro(
@@ -105,17 +143,33 @@ let package = Package(
105143
name: "StructuredQueriesTestSupport",
106144
dependencies: [
107145
"StructuredQueriesCore",
108-
.product(name: "CustomDump", package: "swift-custom-dump"),
109-
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
146+
.product(
147+
name: "CustomDump",
148+
package: "swift-custom-dump",
149+
condition: .when(traits: ["StructuredQueriesCustomDump"])
150+
),
151+
.product(
152+
name: "InlineSnapshotTesting",
153+
package: "swift-snapshot-testing-with-traits",
154+
condition: .when(traits: ["StructuredQueriesSnapshotTesting"])
155+
),
110156
]
111157
),
112158
.testTarget(
113159
name: "StructuredQueriesMacrosTests",
114160
dependencies: [
115161
"StructuredQueriesMacros",
116162
"StructuredQueriesSQLiteMacros",
117-
.product(name: "IssueReporting", package: "xctest-dynamic-overlay"),
118-
.product(name: "MacroTesting", package: "swift-macro-testing"),
163+
.product(
164+
name: "IssueReporting",
165+
package: "xctest-dynamic-overlay",
166+
condition: .when(traits: ["StructuredQueriesIssueReporting"])
167+
),
168+
.product(
169+
name: "MacroTesting",
170+
package: "swift-macro-testing-with-traits",
171+
condition: .when(traits: ["StructuredQueriesMacroTesting"])
172+
),
119173
]
120174
),
121175
.testTarget(
@@ -125,9 +179,21 @@ let package = Package(
125179
"StructuredQueriesSQLite",
126180
"StructuredQueriesTestSupport",
127181
"_StructuredQueriesSQLite",
128-
.product(name: "CustomDump", package: "swift-custom-dump"),
129-
.product(name: "Dependencies", package: "swift-dependencies"),
130-
.product(name: "InlineSnapshotTesting", package: "swift-snapshot-testing"),
182+
.product(
183+
name: "CustomDump",
184+
package: "swift-custom-dump",
185+
condition: .when(traits: ["StructuredQueriesCustomDump"])
186+
),
187+
.product(
188+
name: "Dependencies",
189+
package: "swift-dependencies",
190+
condition: .when(traits: ["StructuredQueriesDependencies"])
191+
),
192+
.product(
193+
name: "InlineSnapshotTesting",
194+
package: "swift-snapshot-testing-with-traits",
195+
condition: .when(traits: ["StructuredQueriesSnapshotTesting"])
196+
),
131197
]
132198
),
133199

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@
77

88
A library for building SQL in a safe, expressive, and composable manner.
99

10+
>[!NOTE]
11+
>This package is a fork of [swift-structured-queries](https://github.com/pointfreeco/swift-structured-queries) with additional traits for opt-in features, making it more _composable_. Upstream is merged sporadically.
12+
>
13+
>### Why does this fork exist?
14+
>
15+
>[Point-Free](https://www.pointfree.co) make good software and tools, but often their packages come with dependencies on the rest of the Point-Free ecosystem for entirely optional behaviour. So even if you don't want or need those dependencies, you have them anyway. Wrapping optional behaviour in traits is easy, but unfortunately there are bugs in Xcode (up to and including 26.0) and it doesn't respect default enabled traits. So were Point-Free to accept a PR with these traits it would be a backwards-incompatible change as far as Xcode is concerned, hence this fork.
16+
>
17+
> To run unit tests successfully for this package you will need to enable several traits:
18+
>
19+
>```swift
20+
>swift test --traits StructuredQueriesSnapshotTesting,StructuredQueriesIssueReporting,StructuredQueriesDependencies,StructuredQueriesCustomDump,StructuredQueriesMacroTesting
21+
>```
1022
## Learn more
1123
1224
This library was motivated and designed over the course of many episodes on

Sources/StructuredQueriesCore/Internal/PrettyPrinting.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import Foundation
2-
import IssueReporting
2+
3+
#if canImport(IssueReporting)
4+
import IssueReporting
5+
#endif
36

47
extension QueryFragment {
58
@inlinable
69
@inline(__always)
710
package static var newlineOrSpace: Self {
811
#if DEBUG
9-
return isTesting ? "\n" : " "
12+
#if canImport(IssueReporting)
13+
return isTesting ? "\n" : " "
14+
#else
15+
return "\n"
16+
#endif
1017
#else
1118
return " "
1219
#endif
@@ -16,7 +23,11 @@ extension QueryFragment {
1623
@inline(__always)
1724
package static var newline: Self {
1825
#if DEBUG
19-
return isTesting ? "\n" : ""
26+
#if canImport(IssueReporting)
27+
return isTesting ? "\n" : ""
28+
#else
29+
return "\n"
30+
#endif
2031
#else
2132
return ""
2233
#endif
@@ -27,7 +38,7 @@ extension QueryFragment {
2738
@inline(__always)
2839
#endif
2940
package func indented() -> Self {
30-
#if DEBUG
41+
#if DEBUG && canImport(IssueReporting)
3142
guard isTesting else { return self }
3243
var query = self
3344
query.segments.insert(.sql(" "), at: 0)
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#if canImport(IssueReporting)
2+
3+
import IssueReporting
4+
5+
package func reportIssue(
6+
_ message: @autoclosure () -> String? = nil,
7+
fileID: StaticString = #fileID,
8+
filePath: StaticString = #filePath,
9+
line: UInt = #line,
10+
column: UInt = #column
11+
) {
12+
IssueReporting.reportIssue(
13+
message(), fileID: fileID, filePath: filePath, line: line, column: column)
14+
}
15+
16+
#else
17+
18+
package func reportIssue(
19+
_ message: @autoclosure () -> String? = nil,
20+
fileID: StaticString = #fileID,
21+
filePath: StaticString = #filePath,
22+
line: UInt = #line,
23+
column: UInt = #column
24+
) {
25+
assertionFailure(message() ?? "Nil issue reported", file: fileID, line: line)
26+
}
27+
28+
#endif

Sources/StructuredQueriesCore/QueryBindable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ extension Int64: QueryBindable {
101101
extension String: QueryBindable {
102102
public var queryBinding: QueryBinding { .text(self) }
103103
public init?(queryBinding: QueryBinding) {
104-
guard case let .text(value) = queryBinding else { return nil }
104+
guard case .text(let value) = queryBinding else { return nil }
105105
self = value
106106
}
107107
}

Sources/StructuredQueriesCore/Statements/Insert.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import IssueReporting
2-
31
extension Table {
42
/// Columns referencing the value that would have been inserted in an
53
/// [insert statement](<doc:InsertStatements>) had there been no conflict.

Sources/StructuredQueriesSQLiteCore/FTS5.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import IssueReporting
2-
31
/// A virtual table using the FTS5 extension.
42
///
53
/// Apply this protocol to a `@Table` declaration to introduce [FTS5] helpers.

Sources/StructuredQueriesSQLiteCore/Triggers.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Foundation
2-
import IssueReporting
32

43
extension Table {
54
/// A `CREATE TEMPORARY TRIGGER` statement that executes after a database event.

0 commit comments

Comments
 (0)