Skip to content

Commit 7ab1657

Browse files
committed
wip
1 parent 0d79f07 commit 7ab1657

File tree

2 files changed

+74
-7
lines changed

2 files changed

+74
-7
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,16 @@ reminder is inserted into the database with the following trigger:
179179
```
180180
}
181181
}
182+
183+
184+
## Topics
185+
186+
### Creating temporary triggers
187+
188+
- ``Table/createTemporaryTrigger(_:ifNotExists:after:fileID:line:column:)``
189+
- ``Table/createTemporaryTrigger(_:ifNotExists:before:fileID:line:column:)``
190+
191+
### Touching records
192+
193+
- ``Table/createTemporaryTrigger(_:ifNotExists:afterInsertTouch:fileID:line:column:)``
194+
- ``Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``

Sources/StructuredQueriesCore/Triggers.swift

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ import IssueReporting
44
extension Table {
55
/// A `CREATE TEMPORARY TRIGGER` statement that executes after a database event.
66
///
7+
/// See <doc:Triggers> for more information.
8+
///
79
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
810
/// > provided. If you build your own trigger helper that call this function, then your helper
9-
/// > should also take fileID, line and column arguments and pass them to this function.
11+
/// > should also take `fileID`, `line` and `column` arguments and pass them to this function.
1012
///
1113
/// - Parameters:
1214
/// - name: The trigger's name. By default a unique name is generated depending using the table,
@@ -38,9 +40,11 @@ extension Table {
3840

3941
/// A `CREATE TEMPORARY TRIGGER` statement that executes before a database event.
4042
///
43+
/// See <doc:Triggers> for more information.
44+
///
4145
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
4246
/// > provided. If you build your own trigger helper that call this function, then your helper
43-
/// > should also take fileID, line and column arguments and pass them to this function.
47+
/// > should also take `fileID`, `line` and `column` arguments and pass them to this function.
4448
///
4549
/// - Parameters:
4650
/// - name: The trigger's name. By default a unique name is generated depending using the table,
@@ -73,9 +77,11 @@ extension Table {
7377
/// A `CREATE TEMPORARY TRIGGER` statement that applies additional updates to a row that has just
7478
/// been updated.
7579
///
80+
/// See <doc:Triggers> for more information.
81+
///
7682
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
7783
/// > provided. If you build your own trigger helper that call this function, then your helper
78-
/// > should also take fileID, line and column arguments and pass them to this function.
84+
/// > should also take `fileID`, `line` and `column` arguments and pass them to this function.
7985
///
8086
/// - Parameters:
8187
/// - name: The trigger's name. By default a unique name is generated depending using the table,
@@ -108,12 +114,14 @@ extension Table {
108114
)
109115
}
110116

111-
/// A `CREATE TEMPORARY TRIGGER` statement that updates a datetime column when a row has been updated.
112-
/// been updated.
117+
/// A `CREATE TEMPORARY TRIGGER` statement that updates a datetime column when a row has been
118+
/// updated.
119+
///
120+
/// See <doc:Triggers> for more information.
113121
///
114122
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
115123
/// > provided. If you build your own trigger helper that call this function, then your helper
116-
/// > should also take fileID, line and column arguments and pass them to this function.
124+
/// > should also take `fileID`, `line` and `column` arguments and pass them to this function.
117125
///
118126
/// - Parameters:
119127
/// - name: The trigger's name. By default a unique name is generated depending using the table,
@@ -144,6 +152,24 @@ extension Table {
144152
)
145153
}
146154

155+
/// A `CREATE TEMPORARY TRIGGER` statement that applies additional updates to a row that has just
156+
/// been inserted.
157+
///
158+
/// See <doc:Triggers> for more information.
159+
///
160+
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
161+
/// > provided. If you build your own trigger helper that call this function, then your helper
162+
/// > should also take `fileID`, `line` and `column` arguments and pass them to this function.
163+
///
164+
/// - Parameters:
165+
/// - name: The trigger's name. By default a unique name is generated depending using the table,
166+
/// operation, and source location.
167+
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
168+
/// - updates: The updates to apply after the row has been inserted.
169+
/// - fileID: The source `#fileID` associated with the trigger.
170+
/// - line: The source `#line` associated with the trigger.
171+
/// - column: The source `#column` associated with the trigger.
172+
/// - Returns: A temporary trigger.
147173
public static func createTemporaryTrigger(
148174
_ name: String? = nil,
149175
ifNotExists: Bool = false,
@@ -166,6 +192,24 @@ extension Table {
166192
)
167193
}
168194

195+
/// A `CREATE TEMPORARY TRIGGER` statement that updates a datetime column when a row has been
196+
/// inserted.
197+
///
198+
/// See <doc:Triggers> for more information.
199+
///
200+
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
201+
/// > provided. If you build your own trigger helper that call this function, then your helper
202+
/// > should also take `fileID`, `line` and `column` arguments and pass them to this function.
203+
///
204+
/// - Parameters:
205+
/// - name: The trigger's name. By default a unique name is generated depending using the table,
206+
/// operation, and source location.
207+
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
208+
/// - date: A key path to a datetime column.
209+
/// - fileID: The source `#fileID` associated with the trigger.
210+
/// - line: The source `#line` associated with the trigger.
211+
/// - column: The source `#column` associated with the trigger.
212+
/// - Returns: A temporary trigger.
169213
public static func createTemporaryTrigger<D: _OptionalPromotable<Date?>>(
170214
_ name: String? = nil,
171215
ifNotExists: Bool = false,
@@ -187,6 +231,13 @@ extension Table {
187231
}
188232
}
189233

234+
/// A `CREATE TEMPORARY TRIGGER` statement.
235+
///
236+
/// This type of statement is returned from the
237+
/// `[Table.createTemporaryTrigger]<doc:Table/createTemporaryTrigger(_:ifNotExists:after:fileID:line:column:)>` family of
238+
/// functions.
239+
///
240+
/// To learn more, see <doc:Triggers>.
190241
public struct TemporaryTrigger<On: Table>: Statement {
191242
public typealias From = Never
192243
public typealias Joins = ()
@@ -196,7 +247,10 @@ public struct TemporaryTrigger<On: Table>: Statement {
196247
case before = "BEFORE"
197248
case after = "AFTER"
198249
}
199-
250+
251+
/// The database event used in a trigger.
252+
///
253+
/// To learn more, see <doc:Triggers>.
200254
public struct Operation: QueryExpression {
201255
public typealias QueryValue = ()
202256

0 commit comments

Comments
 (0)