From bf6dc8a907dac8d38e4111475b195695d7d1c2d2 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 8 Oct 2025 12:09:54 -0500 Subject: [PATCH 1/6] Database functions are always non-isolated. --- .../DatabaseFunctionMacro.swift | 4 +- .../TableMacroTests.swift | 67 +++++++++++++++++++ .../CompileTimeTests.swift | 12 ++++ 3 files changed, 81 insertions(+), 2 deletions(-) diff --git a/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift b/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift index 5fc5190a..498c7b20 100644 --- a/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift +++ b/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift @@ -226,12 +226,12 @@ extension DatabaseFunctionMacro: PeerMacro { return [ """ - \(attributes)\(access)\(`static`)var $\(raw: declarationName): \(functionTypeName) { + nonisolated \(attributes)\(access)\(`static`)var $\(raw: declarationName): \(functionTypeName) { \(functionTypeName)(\(declaration.name.trimmed)) } """, """ - \(attributes)\(access)struct \(functionTypeName): \ + nonisolated \(attributes)\(access)struct \(functionTypeName): \ StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = \(raw: representableInputType) public typealias Output = \(representableOutputType) diff --git a/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift b/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift index b6466046..4b997ffb 100644 --- a/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift +++ b/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift @@ -2338,6 +2338,73 @@ extension SnapshotTests { """ } } + + @Test + func nonisolatedStruct() { + assertMacro { + """ + @Table + nonisolated struct Foo { + var title = "" + } + """ + } expansion: { + #""" + nonisolated struct Foo { + var title = "" + + public nonisolated struct TableColumns: nonisolated StructuredQueriesCore.TableDefinition { + public typealias QueryValue = Foo + public let title = StructuredQueriesCore._TableColumn.for("title", keyPath: \QueryValue.title, default: "") + public static var allColumns: [any StructuredQueriesCore.TableColumnExpression] { + var allColumns: [any StructuredQueriesCore.TableColumnExpression] = [] + allColumns.append(contentsOf: QueryValue.columns.title._allColumns) + return allColumns + } + public static var writableColumns: [any StructuredQueriesCore.WritableTableColumnExpression] { + var writableColumns: [any StructuredQueriesCore.WritableTableColumnExpression] = [] + writableColumns.append(contentsOf: QueryValue.columns.title._writableColumns) + return writableColumns + } + public var queryFragment: QueryFragment { + "\(self.title)" + } + } + + public nonisolated struct Selection: nonisolated StructuredQueriesCore.TableExpression { + public typealias QueryValue = Foo + public let allColumns: [any StructuredQueriesCore.QueryExpression] + public init( + title: some StructuredQueriesCore.QueryExpression = Swift.String(queryOutput: "") + ) { + var allColumns: [any StructuredQueriesCore.QueryExpression] = [] + allColumns.append(contentsOf: title._allColumns) + self.allColumns = allColumns + } + } + } + + nonisolated extension Foo: StructuredQueriesCore.Table, nonisolated StructuredQueriesCore.PartialSelectStatement { + public typealias QueryValue = Self + public typealias From = Swift.Never + public nonisolated static var columns: TableColumns { + TableColumns() + } + public nonisolated static var _columnWidth: Int { + var columnWidth = 0 + columnWidth += Swift.String._columnWidth + return columnWidth + } + public nonisolated static var tableName: String { + "foos" + } + public nonisolated init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws { + self.title = try decoder.decode(Swift.String.self) ?? "" + } + } + """# + } + } } @Test func willSet() { diff --git a/Tests/StructuredQueriesTests/CompileTimeTests.swift b/Tests/StructuredQueriesTests/CompileTimeTests.swift index abd83942..8bfde00d 100644 --- a/Tests/StructuredQueriesTests/CompileTimeTests.swift +++ b/Tests/StructuredQueriesTests/CompileTimeTests.swift @@ -95,3 +95,15 @@ private func functionWithLotsOfArguments( a12: Foo? ) { } + +@Table private struct NonisolatedTable { + var title = "" +} +@Table private struct NonisolatedPrimaryKeyedTable { + let id: Int + var title = "" +} +@Selection private struct NonisolatedSelection { + let id: Int + var title = "" +} From 8135c1fc4bd8753cfd635e2e7fd08e5fa364e2b3 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 8 Oct 2025 12:12:00 -0500 Subject: [PATCH 2/6] wip --- .../StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift b/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift index 498c7b20..ff0f7bb7 100644 --- a/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift +++ b/Sources/StructuredQueriesSQLiteMacros/DatabaseFunctionMacro.swift @@ -226,12 +226,12 @@ extension DatabaseFunctionMacro: PeerMacro { return [ """ - nonisolated \(attributes)\(access)\(`static`)var $\(raw: declarationName): \(functionTypeName) { + \(attributes)\(access)\(`static`)\(nonisolated)var $\(raw: declarationName): \(functionTypeName) { \(functionTypeName)(\(declaration.name.trimmed)) } """, """ - nonisolated \(attributes)\(access)struct \(functionTypeName): \ + \(attributes)\(access)\(nonisolated)struct \(functionTypeName): \ StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = \(raw: representableInputType) public typealias Output = \(representableOutputType) From e661968441697002df54d66ecb2a41b6cd99f5aa Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 8 Oct 2025 12:12:52 -0500 Subject: [PATCH 3/6] wip --- Sources/StructuredQueriesSQLiteMacros/Nonisolated.swift | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Sources/StructuredQueriesSQLiteMacros/Nonisolated.swift diff --git a/Sources/StructuredQueriesSQLiteMacros/Nonisolated.swift b/Sources/StructuredQueriesSQLiteMacros/Nonisolated.swift new file mode 100644 index 00000000..34418215 --- /dev/null +++ b/Sources/StructuredQueriesSQLiteMacros/Nonisolated.swift @@ -0,0 +1,7 @@ +import SwiftSyntax + +#if compiler(>=6.1) + let nonisolated: TokenSyntax? = .keyword(.nonisolated, trailingTrivia: .space) +#else + let nonisolated: TokenSyntax? = nil +#endif From 7e2e3757f1b656ba5a9f3ea3d70f9a690eac669c Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 8 Oct 2025 13:58:06 -0500 Subject: [PATCH 4/6] update tests --- .../DatabaseFunctionMacroTests.swift | 84 +++++++++---------- .../TableMacroTests.swift | 6 +- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Tests/StructuredQueriesMacrosTests/DatabaseFunctionMacroTests.swift b/Tests/StructuredQueriesMacrosTests/DatabaseFunctionMacroTests.swift index 4ffdce05..09f50bde 100644 --- a/Tests/StructuredQueriesMacrosTests/DatabaseFunctionMacroTests.swift +++ b/Tests/StructuredQueriesMacrosTests/DatabaseFunctionMacroTests.swift @@ -19,11 +19,11 @@ extension SnapshotTests { Date() } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "currentDate" @@ -71,11 +71,11 @@ extension SnapshotTests { Date() } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "current_date" @@ -123,11 +123,11 @@ extension SnapshotTests { strings.map { $0.capitalized } } - var $jsonCapitalize: __macro_local_14jsonCapitalizefMu_ { + nonisolated var $jsonCapitalize: __macro_local_14jsonCapitalizefMu_ { __macro_local_14jsonCapitalizefMu_(jsonCapitalize) } - struct __macro_local_14jsonCapitalizefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_14jsonCapitalizefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = [String].JSONRepresentation public typealias Output = [String].JSONRepresentation public let name = "jsonCapitalize" @@ -181,11 +181,11 @@ extension SnapshotTests { 42 } - var $fortyTwo: __macro_local_8fortyTwofMu_ { + nonisolated var $fortyTwo: __macro_local_8fortyTwofMu_ { __macro_local_8fortyTwofMu_(fortyTwo) } - struct __macro_local_8fortyTwofMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_8fortyTwofMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Int public let name = "fortyTwo" @@ -233,11 +233,11 @@ extension SnapshotTests { dateFormatter.date(from: format) } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = String public typealias Output = Date? public let name = "currentDate" @@ -291,11 +291,11 @@ extension SnapshotTests { dateFormatter.date(from: format) } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = String public typealias Output = Date? public let name = "currentDate" @@ -349,11 +349,11 @@ extension SnapshotTests { dateFormatter.date(from: format) } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = String public typealias Output = Date? public let name = "currentDate" @@ -407,11 +407,11 @@ extension SnapshotTests { dateFormatter.date(from: format) } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = String public typealias Output = Date? public let name = "currentDate" @@ -465,11 +465,11 @@ extension SnapshotTests { first + second } - var $concat: __macro_local_6concatfMu_ { + nonisolated var $concat: __macro_local_6concatfMu_ { __macro_local_6concatfMu_(concat) } - struct __macro_local_6concatfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_6concatfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = (String, String) public typealias Output = String public let name = "concat" @@ -545,11 +545,11 @@ extension SnapshotTests { dateFormatter.date(from: format) } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = String? public typealias Output = Date? public let name = "currentDate" @@ -603,11 +603,11 @@ extension SnapshotTests { Date() } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "currentDate" @@ -659,11 +659,11 @@ extension SnapshotTests { Date() } - var $currentDate: __macro_local_11currentDatefMu_ { + nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "currentDate" @@ -715,11 +715,11 @@ extension SnapshotTests { Date() } - public var $currentDate: __macro_local_11currentDatefMu_ { + public nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - public struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + public nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "currentDate" @@ -767,11 +767,11 @@ extension SnapshotTests { Date() } - static var $currentDate: __macro_local_11currentDatefMu_ { + static nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "currentDate" @@ -842,11 +842,11 @@ extension SnapshotTests { Date() } - @available(*, unavailable) var $currentDate: __macro_local_11currentDatefMu_ { + @available(*, unavailable) nonisolated var $currentDate: __macro_local_11currentDatefMu_ { __macro_local_11currentDatefMu_(currentDate) } - @available(*, unavailable) struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + @available(*, unavailable) nonisolated struct __macro_local_11currentDatefMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Date public let name = "currentDate" @@ -894,11 +894,11 @@ extension SnapshotTests { 42 } - public var $default: __macro_local_7defaultfMu_ { + public nonisolated var $default: __macro_local_7defaultfMu_ { __macro_local_7defaultfMu_(`default`) } - public struct __macro_local_7defaultfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + public nonisolated struct __macro_local_7defaultfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Int public let name = "default" @@ -946,11 +946,11 @@ extension SnapshotTests { print("...") } - public var $void: __macro_local_4voidfMu_ { + public nonisolated var $void: __macro_local_4voidfMu_ { __macro_local_4voidfMu_(void) } - public struct __macro_local_4voidfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + public nonisolated struct __macro_local_4voidfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Swift.Void public let name = "void" @@ -993,11 +993,11 @@ extension SnapshotTests { throw Failure() } - public var $void: __macro_local_4voidfMu_ { + public nonisolated var $void: __macro_local_4voidfMu_ { __macro_local_4voidfMu_(void) } - public struct __macro_local_4voidfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + public nonisolated struct __macro_local_4voidfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = () public typealias Output = Swift.Void public let name = "void" @@ -1053,11 +1053,11 @@ extension SnapshotTests { Swift.min(x, y) } - var $min: __macro_local_3minfMu_ { + nonisolated var $min: __macro_local_3minfMu_ { __macro_local_3minfMu_(min) } - struct __macro_local_3minfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_3minfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = (Int, Int) public typealias Output = Swift.Void public let name = "min" @@ -1120,11 +1120,11 @@ extension SnapshotTests { Swift.min(x, y) } - var $min: __macro_local_3minfMu_ { + nonisolated var $min: __macro_local_3minfMu_ { __macro_local_3minfMu_(min) } - struct __macro_local_3minfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_3minfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = (Int, Int) public typealias Output = Swift.Void public let name = "min" @@ -1184,11 +1184,11 @@ extension SnapshotTests { !reminder.title.isEmpty || override } - var $isValid: __macro_local_7isValidfMu_ { + nonisolated var $isValid: __macro_local_7isValidfMu_ { __macro_local_7isValidfMu_(isValid) } - struct __macro_local_7isValidfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { + nonisolated struct __macro_local_7isValidfMu_: StructuredQueriesSQLiteCore.ScalarDatabaseFunction { public typealias Input = (Reminder, Bool) public typealias Output = Bool public let name = "isValid" diff --git a/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift b/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift index 4b997ffb..d92589bf 100644 --- a/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift +++ b/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift @@ -2353,7 +2353,7 @@ extension SnapshotTests { nonisolated struct Foo { var title = "" - public nonisolated struct TableColumns: nonisolated StructuredQueriesCore.TableDefinition { + public nonisolated struct TableColumns: StructuredQueriesCore.TableDefinition { public typealias QueryValue = Foo public let title = StructuredQueriesCore._TableColumn.for("title", keyPath: \QueryValue.title, default: "") public static var allColumns: [any StructuredQueriesCore.TableColumnExpression] { @@ -2371,7 +2371,7 @@ extension SnapshotTests { } } - public nonisolated struct Selection: nonisolated StructuredQueriesCore.TableExpression { + public nonisolated struct Selection: StructuredQueriesCore.TableExpression { public typealias QueryValue = Foo public let allColumns: [any StructuredQueriesCore.QueryExpression] public init( @@ -2384,7 +2384,7 @@ extension SnapshotTests { } } - nonisolated extension Foo: StructuredQueriesCore.Table, nonisolated StructuredQueriesCore.PartialSelectStatement { + nonisolated extension Foo: StructuredQueriesCore.Table, StructuredQueriesCore.PartialSelectStatement { public typealias QueryValue = Self public typealias From = Swift.Never public nonisolated static var columns: TableColumns { From 699c9aa686e1438f17007d89ad55a40f0585f31b Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 8 Oct 2025 13:58:59 -0500 Subject: [PATCH 5/6] clean up --- .../TableMacroTests.swift | 67 ------------------- .../CompileTimeTests.swift | 12 ---- 2 files changed, 79 deletions(-) diff --git a/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift b/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift index d92589bf..b6466046 100644 --- a/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift +++ b/Tests/StructuredQueriesMacrosTests/TableMacroTests.swift @@ -2338,73 +2338,6 @@ extension SnapshotTests { """ } } - - @Test - func nonisolatedStruct() { - assertMacro { - """ - @Table - nonisolated struct Foo { - var title = "" - } - """ - } expansion: { - #""" - nonisolated struct Foo { - var title = "" - - public nonisolated struct TableColumns: StructuredQueriesCore.TableDefinition { - public typealias QueryValue = Foo - public let title = StructuredQueriesCore._TableColumn.for("title", keyPath: \QueryValue.title, default: "") - public static var allColumns: [any StructuredQueriesCore.TableColumnExpression] { - var allColumns: [any StructuredQueriesCore.TableColumnExpression] = [] - allColumns.append(contentsOf: QueryValue.columns.title._allColumns) - return allColumns - } - public static var writableColumns: [any StructuredQueriesCore.WritableTableColumnExpression] { - var writableColumns: [any StructuredQueriesCore.WritableTableColumnExpression] = [] - writableColumns.append(contentsOf: QueryValue.columns.title._writableColumns) - return writableColumns - } - public var queryFragment: QueryFragment { - "\(self.title)" - } - } - - public nonisolated struct Selection: StructuredQueriesCore.TableExpression { - public typealias QueryValue = Foo - public let allColumns: [any StructuredQueriesCore.QueryExpression] - public init( - title: some StructuredQueriesCore.QueryExpression = Swift.String(queryOutput: "") - ) { - var allColumns: [any StructuredQueriesCore.QueryExpression] = [] - allColumns.append(contentsOf: title._allColumns) - self.allColumns = allColumns - } - } - } - - nonisolated extension Foo: StructuredQueriesCore.Table, StructuredQueriesCore.PartialSelectStatement { - public typealias QueryValue = Self - public typealias From = Swift.Never - public nonisolated static var columns: TableColumns { - TableColumns() - } - public nonisolated static var _columnWidth: Int { - var columnWidth = 0 - columnWidth += Swift.String._columnWidth - return columnWidth - } - public nonisolated static var tableName: String { - "foos" - } - public nonisolated init(decoder: inout some StructuredQueriesCore.QueryDecoder) throws { - self.title = try decoder.decode(Swift.String.self) ?? "" - } - } - """# - } - } } @Test func willSet() { diff --git a/Tests/StructuredQueriesTests/CompileTimeTests.swift b/Tests/StructuredQueriesTests/CompileTimeTests.swift index 8bfde00d..abd83942 100644 --- a/Tests/StructuredQueriesTests/CompileTimeTests.swift +++ b/Tests/StructuredQueriesTests/CompileTimeTests.swift @@ -95,15 +95,3 @@ private func functionWithLotsOfArguments( a12: Foo? ) { } - -@Table private struct NonisolatedTable { - var title = "" -} -@Table private struct NonisolatedPrimaryKeyedTable { - let id: Int - var title = "" -} -@Selection private struct NonisolatedSelection { - let id: Int - var title = "" -} From 315ee36ab23bbc9ad89736c7a15db2884b00dd05 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Wed, 8 Oct 2025 14:12:32 -0500 Subject: [PATCH 6/6] docs --- .../Documentation.docc/Articles/DefiningYourSchema.md | 4 ++++ .../Documentation.docc/Articles/QueryCookbook.md | 8 ++++++++ .../Documentation.docc/Articles/CustomFunctions.md | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/Sources/StructuredQueriesCore/Documentation.docc/Articles/DefiningYourSchema.md b/Sources/StructuredQueriesCore/Documentation.docc/Articles/DefiningYourSchema.md index 8e6a9720..b84137b0 100644 --- a/Sources/StructuredQueriesCore/Documentation.docc/Articles/DefiningYourSchema.md +++ b/Sources/StructuredQueriesCore/Documentation.docc/Articles/DefiningYourSchema.md @@ -51,6 +51,10 @@ To define a Swift data type that represents this table, one can use the `@Table` } ``` +> Note: If your project is using [default main actor isolation] then you further need to annotate +> your struct as `nonisolated`. +[default main actor isolation]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0466-control-default-actor-isolation.md + Note that the struct's field names match the column tables of the table exactly. In order to support property names that differ from the columns names, you can use the `@Column` macro. See the section below, , for more information on how to customize your diff --git a/Sources/StructuredQueriesCore/Documentation.docc/Articles/QueryCookbook.md b/Sources/StructuredQueriesCore/Documentation.docc/Articles/QueryCookbook.md index 85ffa293..5da62973 100644 --- a/Sources/StructuredQueriesCore/Documentation.docc/Articles/QueryCookbook.md +++ b/Sources/StructuredQueriesCore/Documentation.docc/Articles/QueryCookbook.md @@ -50,6 +50,10 @@ extension Reminder { } ``` +> Note: If your project is using [default main actor isolation] then you further need to annotate +> your extension as `nonisolated`, or define the helpers directly in the declaration of the struct. +[default main actor isolation]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0466-control-default-actor-isolation.md + Then these helpers can be used when composing together a larger, more complex query. For example, we can select all non-deleted lists with the count of all non-deleted reminders in each list like so: @@ -131,6 +135,10 @@ extension Reminder.TableColumns { } ``` +> Note: If your project is using [default main actor isolation] then you further need to annotate +> your extension as `nonisolated`. +[default main actor isolation]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0466-control-default-actor-isolation.md + Then you can use these helpers when building a query. For example, you can use ``PrimaryKeyedTableDefinition/count(distinct:filter:)`` to count the number of past due, current and scheduled reminders in one single query like so: diff --git a/Sources/StructuredQueriesSQLiteCore/Documentation.docc/Articles/CustomFunctions.md b/Sources/StructuredQueriesSQLiteCore/Documentation.docc/Articles/CustomFunctions.md index cb72050a..7d4b76b8 100644 --- a/Sources/StructuredQueriesSQLiteCore/Documentation.docc/Articles/CustomFunctions.md +++ b/Sources/StructuredQueriesSQLiteCore/Documentation.docc/Articles/CustomFunctions.md @@ -18,6 +18,10 @@ func exclaim(_ string: String) -> String { } ``` +> Note: If your project is using [default main actor isolation] then you further need to annotate +> your function as `nonisolated`. +[default main actor isolation]: https://github.com/swiftlang/swift-evolution/blob/main/proposals/0466-control-default-actor-isolation.md + And will be immediately callable in a query by prefixing the function with `$`: ```swift