Skip to content

Commit f0cc943

Browse files
authored
Merge branch 'main' into more-association-docs
2 parents 3d21de2 + 5608aaf commit f0cc943

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2023
-771
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
strategy:
3535
matrix:
3636
swift:
37+
- '6.0'
3738
- '6.1'
3839
runs-on: ubuntu-latest
3940
container: swift:${{ matrix.swift }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ DerivedData/
77
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
88
.netrc
99
Package.resolved
10-
db.sqlite
10+
*.sqlite

Sources/StructuredQueries/Macros.swift

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ import StructuredQueriesCore
99
conformances: Table,
1010
PartialSelectStatement,
1111
PrimaryKeyedTable,
12-
names: named(TableColumns),
13-
named(From),
14-
named(Draft),
12+
names: named(From),
1513
named(columns),
1614
named(init(_:)),
1715
named(init(decoder:)),
1816
named(QueryValue),
1917
named(schemaName),
2018
named(tableName)
2119
)
22-
@attached(
23-
memberAttribute
24-
)
20+
@attached(member, names: named(Draft), named(TableColumns))
21+
@attached(memberAttribute)
2522
public macro Table(
26-
_ name: String? = nil,
27-
schema schemaName: String? = nil
23+
_ name: String = "",
24+
schema schemaName: String = ""
2825
) =
2926
#externalMacro(
3027
module: "StructuredQueriesMacros",
@@ -38,9 +35,9 @@ public macro Table(
3835
/// - representableType: A type that represents the property type in a query expression. For types
3936
/// that don't have a single representation in SQL, like `Date` and `UUID`.
4037
/// - primaryKey: The column is its table's auto-incrementing primary key.
41-
@attached(accessor, names: named(willSet))
38+
@attached(peer)
4239
public macro Column(
43-
_ name: String? = nil,
40+
_ name: String = "",
4441
as representableType: (any QueryRepresentable.Type)? = nil,
4542
primaryKey: Bool = false
4643
) =
@@ -52,7 +49,7 @@ public macro Column(
5249
/// Tells Structured Queries not to consider the annotated property a column of the table
5350
///
5451
/// Like SwiftData's `@Transient` macro, but for SQL.
55-
@attached(accessor, names: named(willSet))
52+
@attached(peer)
5653
public macro Ephemeral() =
5754
#externalMacro(
5855
module: "StructuredQueriesMacros",
@@ -95,6 +92,7 @@ public macro Ephemeral() =
9592
names: named(Columns),
9693
named(init(decoder:))
9794
)
95+
@attached(member, names: named(Columns))
9896
public macro Selection() =
9997
#externalMacro(
10098
module: "StructuredQueriesMacros",
@@ -135,21 +133,9 @@ public macro sql<QueryValue>(
135133
) -> SQLQueryExpression<QueryValue> =
136134
#externalMacro(module: "StructuredQueriesMacros", type: "SQLMacro")
137135

138-
// NB: Due to a bug in Swift, this macro is expanded internally by the '@Table' macro.
139-
// @attached(
140-
// memberAttribute
141-
// )
142-
// @attached(
143-
// extension,
144-
// conformances: Table,
145-
// names: named(TableColumns),
146-
// named(columns),
147-
// named(init(_:)),
148-
// named(init(decoder:)),
149-
// named(tableName)
150-
// )
151-
// public macro _Draft<T: Table>(_: T.Type) =
152-
// #externalMacro(
153-
// module: "StructuredQueriesMacros",
154-
// type: "TableMacro"
155-
// )
136+
@freestanding(expression)
137+
public macro sql(
138+
_ queryFragment: QueryFragment,
139+
as queryValueType: Any.Type = Any.self
140+
) -> SQLQueryExpression<Any> =
141+
#externalMacro(module: "StructuredQueriesMacros", type: "SQLMacro")

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ and will decode data from the database using the `RawRepresentable` conformance
189189
@Row {
190190
@Column {
191191
```swift
192-
Reminder.insert(
192+
Reminder.insert {
193193
Reminder.Draft(
194194
title: "Get haircut",
195195
priority: .medium
196196
)
197-
)
197+
}
198198
```
199199
}
200200
@Column {
@@ -240,12 +240,12 @@ With that you can insert reminders with notes like so:
240240
@Row {
241241
@Column {
242242
```swift
243-
Reminder.insert(
243+
Reminder.insert {
244244
Reminder.Draft(
245245
title: "Get groceries",
246246
notes: ["Milk", "Eggs", "Bananas"]
247247
)
248-
)
248+
}
249249
```
250250
}
251251
@Column {
@@ -342,9 +342,9 @@ And StructuredQueries will take care of formatting the value for the database:
342342
@Row {
343343
@Column {
344344
```swift
345-
Reminder.insert(
345+
Reminder.insert {
346346
Reminder.Draft(date: Date())
347-
)
347+
}
348348
```
349349
}
350350
@Column {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ capable of. See <doc:SelectStatements> for more examples of select statements, a
305305
The library provides the tools necessary to construct type-safe insert statements in SQL, including
306306
inserting an entire value into a table, inserting only a subset of rows, as well as what to do on
307307
conflicts. Using the `Reminder` data type from above, we can insert data for all of its rows using
308-
the ``Table/insert(or:_:values:onConflict:)`` method:
308+
the ``Table/insert(or:_:values:onConflict:where:doUpdate:where:)`` method:
309309

310310
@Row {
311311
@Column {
@@ -338,10 +338,11 @@ mechanism). The second trailing closure is a list of values that you want to ins
338338
and the number of columns and data type of each column must match what is specified in the first
339339
trailing closure.
340340

341-
You can provide a 3rd trailing closure to ``Table/insert(or:_:values:onConflict:)`` to describe what
342-
to do in case there is a conflict while inserting data. For example, suppose we had a unique index
343-
on the "title" column of the reminders table. Then when inserting a value with a repeated title we
344-
could resolve the conflict by appending the string `" (Copy)"` to the title:
341+
You can provide a 3rd trailing closure to
342+
``Table/insert(or:_:values:onConflict:where:doUpdate:where:)`` to describe what to do in case there
343+
is a conflict while inserting data. For example, suppose we had a unique index on the "title" column
344+
of the reminders table. Then when inserting a value with a repeated title we could resolve the
345+
conflict by appending the string `" (Copy)"` to the title:
345346

346347
@Row {
347348
@Column {

0 commit comments

Comments
 (0)