You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sources/StructuredQueriesCore/Triggers.swift
+81-12Lines changed: 81 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,11 @@ import Foundation
2
2
import IssueReporting
3
3
4
4
extensionTable{
5
-
/// A `CREATE TEMPORARY TRIGGER` statement.
5
+
/// A `CREATE TEMPORARY TRIGGER` statement that executes after a database event.
6
6
///
7
-
/// > Important: TODO: explain how implicit names are handled and how trigger helpers should always take file/line/column. and put in name/file/line/column parameters.
7
+
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
8
+
/// > 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.
8
10
///
9
11
/// - Parameters:
10
12
/// - name: The trigger's name. By default a unique name is generated depending using the table,
@@ -27,14 +29,63 @@ extension Table {
27
29
name: name,
28
30
ifNotExists: ifNotExists,
29
31
operation: operation,
32
+
when:.after,
30
33
fileID: fileID,
31
34
line: line,
32
35
column: column
33
36
)
34
37
}
35
38
36
-
// TODO: write tests on these below:
39
+
/// A `CREATE TEMPORARY TRIGGER` statement that executes before a database event.
40
+
///
41
+
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
42
+
/// > 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.
44
+
///
45
+
/// - Parameters:
46
+
/// - name: The trigger's name. By default a unique name is generated depending using the table,
47
+
/// operation, and source location.
48
+
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
49
+
/// - operation: The trigger's operation.
50
+
/// - fileID: The source `#fileID` associated with the trigger.
51
+
/// - line: The source `#line` associated with the trigger.
52
+
/// - column: The source `#column` associated with the trigger.
53
+
/// - Returns: A temporary trigger.
54
+
publicstaticfunc createTemporaryTrigger(
55
+
_ name:String?=nil,
56
+
ifNotExists:Bool=false,
57
+
before operation:TemporaryTrigger<Self>.Operation,
58
+
fileID:StaticString= #fileID,
59
+
line:UInt= #line,
60
+
column:UInt= #column
61
+
)->TemporaryTrigger<Self>{
62
+
TemporaryTrigger(
63
+
name: name,
64
+
ifNotExists: ifNotExists,
65
+
operation: operation,
66
+
when:.before,
67
+
fileID: fileID,
68
+
line: line,
69
+
column: column
70
+
)
71
+
}
37
72
73
+
/// A `CREATE TEMPORARY TRIGGER` statement that applies additional updates to a row that has just
74
+
/// been updated.
75
+
///
76
+
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
77
+
/// > 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.
79
+
///
80
+
/// - Parameters:
81
+
/// - name: The trigger's name. By default a unique name is generated depending using the table,
82
+
/// operation, and source location.
83
+
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
84
+
/// - updates: The updates to apply after the row has been updated.
85
+
/// - fileID: The source `#fileID` associated with the trigger.
86
+
/// - line: The source `#line` associated with the trigger.
87
+
/// - column: The source `#column` associated with the trigger.
88
+
/// - Returns: A temporary trigger.
38
89
publicstaticfunc createTemporaryTrigger(
39
90
_ name:String?=nil,
40
91
ifNotExists:Bool=false,
@@ -57,7 +108,22 @@ extension Table {
57
108
)
58
109
}
59
110
60
-
// TODO: Touchable protocol with Date: Touchable, UUID: Touchable, ?
111
+
/// A `CREATE TEMPORARY TRIGGER` statement that updates a datetime column when a row has been updated.
112
+
/// been updated.
113
+
///
114
+
/// > Important: A name for the trigger is automatically derived from the arguments if one is not
115
+
/// > 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.
117
+
///
118
+
/// - Parameters:
119
+
/// - name: The trigger's name. By default a unique name is generated depending using the table,
120
+
/// operation, and source location.
121
+
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
122
+
/// - date: A key path to a datetime column.
123
+
/// - fileID: The source `#fileID` associated with the trigger.
124
+
/// - line: The source `#line` associated with the trigger.
125
+
/// - column: The source `#column` associated with the trigger.
0 commit comments