@@ -2,8 +2,10 @@ import StructuredQueriesCore
22
33/// Defines and implements a conformance to the ``/StructuredQueriesCore/Table`` protocol.
44///
5- /// - Parameter name: The table's name. Defaults to a lower-camel-case pluralization of the type,
6- /// _e.g._ `RemindersList` becomes `"remindersLists"`.
5+ /// - Parameters
6+ /// - name: The table's name. Defaults to a lower-camel-case pluralization of the type,
7+ /// _e.g._ `RemindersList` becomes `"remindersLists"`.
8+ /// - schemaName: The table's schema name.
79@attached (
810 extension,
911 conformances: Table,
@@ -29,6 +31,63 @@ public macro Table(
2931 type: " TableMacro "
3032 )
3133
34+ /// Defines a "selection" of columns that can be decoded from a query.
35+ ///
36+ /// When selecting tables and fields from a query, this data is bundled up into a tuple:
37+ ///
38+ /// ```swift
39+ /// RemindersList
40+ /// .group(by: \.id)
41+ /// .join(Reminder.all) { $0.id == $0.remindersListID }
42+ /// .select { ($0, $1.count()) }
43+ /// // [(RemindersList, Int)]
44+ /// ```
45+ ///
46+ /// The `@Selection` macro allows you to bundle this data up into a dedicated type, instead:
47+ ///
48+ /// ```swift
49+ /// @Selection
50+ /// struct ListWithCount {
51+ /// let list: RemindersList
52+ /// let count: Int
53+ /// }
54+ ///
55+ /// RemindersList
56+ /// .group(by: \.id)
57+ /// .join(Reminder.all) { $0.id == $0.remindersListID }
58+ /// .select { ListWithCount.Columns(list: $0, count: $1.count()) }
59+ /// // [RemindersListWithReminderCount]
60+ /// ```
61+ ///
62+ /// > Tip: `@Selection`s can also be used to build up common table expressions.
63+ ///
64+ /// - Parameter name: The selection's name, _i.e._ for a common table expression. Defaults to a
65+ /// lower-camel-case pluralization of the type, _e.g._ `RemindersList` becomes `"remindersLists"`.
66+ @attached (
67+ extension,
68+ conformances: _Selection,
69+ Table,
70+ PartialSelectStatement,
71+ PrimaryKeyedTable,
72+ names: named ( From) ,
73+ named ( columns) ,
74+ named ( columnWidth) ,
75+ named ( init ( _: ) ) ,
76+ named ( init ( decoder: ) ) ,
77+ named ( QueryValue) ,
78+ named ( schemaName) ,
79+ named ( tableName)
80+ )
81+ @attached ( member, names: named ( Draft) , named ( Selection) , named ( TableColumns) )
82+ @attached ( memberAttribute)
83+ public macro Selection(
84+ _ name: String = " "
85+ ) =
86+ #externalMacro(
87+ module: " StructuredQueriesMacros " ,
88+ type: " TableMacro "
89+ )
90+
3291/// Customizes a column generated by the ``/StructuredQueriesCore/Table`` protocol.
3392///
3493/// - Parameters:
@@ -73,53 +132,6 @@ public macro Ephemeral() =
73132 type: " EphemeralMacro "
74133 )
75134
76- /// Defines the ability for a type to be selected from a query.
77- ///
78- /// When selecting tables and fields from a query, this data is bundled up into a tuple:
79- ///
80- /// ```swift
81- /// RemindersList
82- /// .group(by: \.id)
83- /// .join(Reminder.all) { $0.id == $0.remindersListID }
84- /// .select { ($0, $1.count()) }
85- /// // [(RemindersList, Int)]
86- /// ```
87- ///
88- /// The `@Selection` macro allows you to bundle this data up into a dedicated type, instead:
89- ///
90- /// ```swift
91- /// @Selection
92- /// struct ListWithCount {
93- /// let list: RemindersList
94- /// let count: Int
95- /// }
96- ///
97- /// RemindersList
98- /// .group(by: \.id)
99- /// .join(Reminder.all) { $0.id == $0.remindersListID }
100- /// .select { ListWithCount.Columns(list: $0, count: $1.count()) }
101- /// // [RemindersListWithReminderCount]
102- /// ```
103- ///
104- /// The ``Table(_:)`` and `@Selection` macros can be composed together to describe a virtual table
105- /// or common table expression.
106- @attached (
107- extension,
108- conformances: _Selection,
109- names: named ( Columns) ,
110- named ( init ( decoder: ) )
111- )
112- @attached ( member, names: named ( Columns) )
113- @available ( iOS, deprecated: 9999 , renamed: " Table " )
114- @available ( macOS, deprecated: 9999 , renamed: " Table " )
115- @available ( tvOS, deprecated: 9999 , renamed: " Table " )
116- @available ( watchOS, deprecated: 9999 , renamed: " Table " )
117- public macro Selection( ) =
118- #externalMacro(
119- module: " StructuredQueriesMacros " ,
120- type: " SelectionMacro "
121- )
122-
123135/// Explicitly bind a value to a query.
124136///
125137/// This macro explicitly binds a Swift value to a query. This is required when binding a value with
0 commit comments