Skip to content

Commit 0bc5a80

Browse files
committed
wip
1 parent b82b66d commit 0bc5a80

File tree

7 files changed

+52
-40
lines changed

7 files changed

+52
-40
lines changed

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ it's as simple as adding it to your `Package.swift`:
220220

221221
``` swift
222222
dependencies: [
223-
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.17.0"),
223+
.package(url: "https://github.com/pointfreeco/swift-structured-queries", from: "0.22.0"),
224224
]
225225
```
226226

@@ -231,16 +231,21 @@ And then adding the product to any target that needs access to the library:
231231
```
232232

233233
If you are on Swift 6.1 or greater, you can enable package traits that extend the library with
234-
support for other libraries. For example, you can introduce type-safe identifiers to your tables
235-
_via_ [Tagged](https://github.com/pointfreeco/swift-tagged) by enabling the
236-
`StructuredQueriesTagged` trait:
234+
support for other libraries:
235+
236+
* `StructuredQueriesCasePaths`: Adds support for single-table inheritance _via_ "enum" tables by
237+
leveraging the [CasePaths](https://github.com/pointfreeco/swift-case-paths) library.
238+
239+
* `StructuredQueriesTagged`: Adds support for type-safe identifiers _via_
240+
the [Tagged](https://github.com/pointfreeco/swift-tagged) library.
237241

238242
```diff
239243
dependencies: [
240244
.package(
241245
url: "https://github.com/pointfreeco/swift-structured-queries",
242-
from: "0.17.0",
246+
from: "0.22.0",
243247
+ traits: [
248+
+ "StructuredQueriesCasePaths",
244249
+ "StructuredQueriesTagged",
245250
+ ]
246251
),

Sources/StructuredQueriesCore/Documentation.docc/Articles/DefiningYourSchema.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ To enable the trait, specify it in the Package.swift file that depends on Struct
272272
```diff
273273
.package(
274274
url: "https://github.com/pointfreeco/swift-structured-queries",
275-
from: "0.17.0",
275+
from: "0.22.0",
276276
+ traits: ["StructuredQueriesTagged"]
277277
),
278278
```
@@ -385,7 +385,7 @@ struct Reminder {
385385
> Important: Since SQLite has no concept of grouped columns you must remember to flatten all
386386
> groupings into a single list when defining your table's schema. For example, the "CREATE TABLE"
387387
> statement for the `RemindersList` above would look like this:
388-
>
388+
>
389389
> ```sql
390390
> CREATE TABLE "remindersLists" (
391391
> "id" INTEGER PRIMARY KEY,
@@ -414,15 +414,15 @@ You can construct queries that access fields inside column groups using regular
414414
}
415415
}
416416
417-
You can even compare the `timestamps` field directly and its columns will be flattened into a
417+
You can even compare the `timestamps` field directly and its columns will be flattened into a
418418
tuple in SQL:
419419
420420
@Row {
421421
@Column {
422422
```swift
423423
RemindersList
424-
.where {
425-
$0.timestamps <= Timestamps(createdAt: date1, updatedAt: date2)
424+
.where {
425+
$0.timestamps <= Timestamps(createdAt: date1, updatedAt: date2)
426426
}
427427
```
428428
}
@@ -484,9 +484,9 @@ struct Event {
484484
It is possible to use enums as a domain modeling tool for your table schema, which can help you
485485
emulate "inheritance" for your tables without having the burden of using reference types.
486486
487-
As an example, suppose you have a table that represents attachments that can be associated with
487+
As an example, suppose you have a table that represents attachments that can be associated with
488488
other tables, and an attachment can either be a link, a note or an image. One way to model this
489-
is a struct to represent the attachment that holds onto an enum for the different kinds of
489+
is a struct to represent the attachment that holds onto an enum for the different kinds of
490490
attachments supported, annotated with the `@Selection` macro:
491491
492492
```swift
@@ -533,10 +533,10 @@ be decided which case of the `Kind` enum is chosen:
533533
}
534534
@Column {
535535
```sql
536-
SELECT
537-
"attachments"."id",
538-
"attachments"."link",
539-
"attachments"."note",
536+
SELECT
537+
"attachments"."id",
538+
"attachments"."link",
539+
"attachments"."note",
540540
"attachments"."image"
541541
FROM "attachments"
542542
```
@@ -554,13 +554,13 @@ only:
554554
}
555555
@Column {
556556
```sql
557-
SELECT
558-
"attachments"."id",
559-
"attachments"."link",
560-
"attachments"."note",
557+
SELECT
558+
"attachments"."id",
559+
"attachments"."link",
560+
"attachments"."note",
561561
"attachments"."image"
562562
FROM "attachments"
563-
WHERE "attachments"."image" IS NOT NULL
563+
WHERE "attachments"."image" IS NOT NULL
564564
```
565565
}
566566
}
@@ -601,9 +601,9 @@ And further, you can update attachments in the database in the usual way:
601601
@Column {
602602
```sql
603603
UPDATE "attachments"
604-
SET
605-
"link" = NULL,
606-
"note" = 'Goodbye world!',
604+
SET
605+
"link" = NULL,
606+
"note" = 'Goodbye world!',
607607
"image" = NULL
608608
```
609609
}
@@ -627,7 +627,7 @@ can be defined for that data and used in the `image` case:
627627
case note(String)
628628
case image(Attachment.Image)
629629
}
630-
@Selection
630+
@Selection
631631
struct Image {
632632
var caption = ""
633633
var url: URL
@@ -638,7 +638,7 @@ can be defined for that data and used in the `image` case:
638638
> Note: Due to how macros expand it is necessary to fully qualify nested types, e.g.
639639
> `case image(Attachment.Image)`.
640640
641-
To create a SQL table that represents this data type you again must flatten all columns into a
641+
To create a SQL table that represents this data type you again must flatten all columns into a
642642
single list of nullable columns:
643643
644644
```sql
@@ -694,8 +694,8 @@ it's a lot more verbose:
694694
}
695695
```
696696
697-
> Note: The `@available(iOS 26, *)` attributes are required even if targeting iOS 26+, and
698-
> the explicit initializers are required and must accept all arguments from all parent
697+
> Note: The `@available(iOS 26, *)` attributes are required even if targeting iOS 26+, and
698+
> the explicit initializers are required and must accept all arguments from all parent
699699
> classes and pass that to `super.init`.
700700
701701
Enums provide an alternative to this approach that embraces value types, is more concise, and

Sources/StructuredQueriesCore/Optional.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,11 @@ extension Optional: QueryExpression where Wrapped: QueryExpression {
5252
}
5353

5454
public var _allColumns: [any QueryExpression] {
55-
self?._allColumns ?? Array(
56-
repeating: SQLQueryExpression("NULL") as any QueryExpression,
57-
count: Self._columnWidth
58-
)
55+
self?._allColumns
56+
?? Array(
57+
repeating: SQLQueryExpression("NULL") as any QueryExpression,
58+
count: Self._columnWidth
59+
)
5960
}
6061
}
6162

Sources/StructuredQueriesMacros/TableMacro.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ extension TableMacro: ExtensionMacro {
383383
? "TableColumn"
384384
: "_TableColumn"
385385
let tableColumnInitializer = tableColumnType == "_TableColumn" ? ".for" : ""
386-
let defaultParameter = isColumnGroup
386+
let defaultParameter =
387+
isColumnGroup
387388
? ""
388389
: defaultValue.map { ", default: \($0.trimmedDescription)" } ?? ""
389390
func appendColumnProperty(primaryKey: Bool = false) {
@@ -660,7 +661,8 @@ extension TableMacro: ExtensionMacro {
660661
? "TableColumn"
661662
: "_TableColumn"
662663
let tableColumnInitializer = tableColumnType == "_TableColumn" ? ".for" : ""
663-
let defaultParameter = isColumnGroup
664+
let defaultParameter =
665+
isColumnGroup
664666
? ""
665667
: defaultValue.map { ", default: \($0.trimmedDescription)" } ?? ""
666668
func appendColumnProperty(primaryKey: Bool = false) {
@@ -946,7 +948,8 @@ extension TableMacro: MemberMacro {
946948
?? binding.initializer?.value.literalType)
947949
.map { $0.rewritten(selfRewriter) }
948950
var columnQueryOutputType = columnQueryValueType
949-
var isPrimaryKey = primaryKey == nil
951+
var isPrimaryKey =
952+
primaryKey == nil
950953
&& identifier.text == "id"
951954
&& node.attributeName.identifier != "_Draft"
952955
var isColumnGroup = false
@@ -1061,7 +1064,8 @@ extension TableMacro: MemberMacro {
10611064
? "TableColumn"
10621065
: "_TableColumn"
10631066
let tableColumnInitializer = tableColumnType == "_TableColumn" ? ".for" : ""
1064-
let defaultParameter = isColumnGroup
1067+
let defaultParameter =
1068+
isColumnGroup
10651069
? ""
10661070
: defaultValue.map { ", default: \($0.trimmedDescription)" } ?? ""
10671071
func appendColumnProperty(primaryKey: Bool = false) {
@@ -1270,7 +1274,8 @@ extension TableMacro: MemberMacro {
12701274
? "TableColumn"
12711275
: "_TableColumn"
12721276
let tableColumnInitializer = tableColumnType == "_TableColumn" ? ".for" : ""
1273-
let defaultParameter = isColumnGroup
1277+
let defaultParameter =
1278+
isColumnGroup
12741279
? ""
12751280
: defaultValue.map { ", default: \($0.trimmedDescription)" } ?? ""
12761281
func appendColumnProperty(primaryKey: Bool = false) {

Tests/StructuredQueriesTests/NestedTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ extension SnapshotTests {
473473
@Test func reminderListAndReminderCountPayload() {
474474
let baseQuery =
475475
RemindersList
476-
.where { _ in #sql("color > 0") }
476+
.where { _ in #sql("color > 0") }
477477
.join(Reminder.all) { $0.id.eq($1.remindersListID) }
478478
assertQuery(
479479
baseQuery

Tests/StructuredQueriesTests/SelectionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extension SnapshotTests {
77
@Suite struct SelectionTests {
88
@Test func remindersListAndReminderCount() {
99
let baseQuery =
10-
RemindersList
10+
RemindersList
1111
.group(by: \.id)
1212
.limit(2)
1313
.join(Reminder.all) { $0.id.eq($1.remindersListID) }

Tests/StructuredQueriesTests/TriggersTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ extension SnapshotTests {
118118
}
119119

120120
@Test func afterUpdateTouchDate_NestedTimestamps() throws {
121-
try db.execute("""
121+
try db.execute(
122+
"""
122123
CREATE TABLE "episodes" (
123124
"id" INTEGER PRIMARY KEY,
124125
"createdAt" TEXT NOT NULL,

0 commit comments

Comments
 (0)