Skip to content

Commit 71b9d72

Browse files
committed
Use query expression instead
1 parent 5b0a224 commit 71b9d72

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

Sources/StructuredQueriesCore/Triggers.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ extension Table {
128128
/// operation, and source location.
129129
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
130130
/// - dateColumn: A key path to a datetime column.
131-
/// - dateFunction: A database function that returns the current date. Include parentheses in
132-
/// string, i.e. `"customDate()"`.
131+
/// - dateFunction: A database function that returns the current date, _e.g._,
132+
/// `#sql("date('subsec'))"`.
133133
/// - expression: The expression used to generate the datetime.
134134
/// - fileID: The source `#fileID` associated with the trigger.
135135
/// - line: The source `#line` associated with the trigger.
@@ -139,7 +139,7 @@ extension Table {
139139
_ name: String? = nil,
140140
ifNotExists: Bool = false,
141141
afterUpdateTouch dateColumn: KeyPath<TableColumns, TableColumn<Self, D>>,
142-
date dateFunction: StaticString = "datetime('subsec')",
142+
date dateFunction: any QueryExpression<D> = SQLQueryExpression<D>("date('subsec')"),
143143
fileID: StaticString = #fileID,
144144
line: UInt = #line,
145145
column: UInt = #column
@@ -148,7 +148,7 @@ extension Table {
148148
name,
149149
ifNotExists: ifNotExists,
150150
afterUpdateTouch: {
151-
$0[dynamicMember: dateColumn] = SQLQueryExpression("\(raw: dateFunction.description)")
151+
$0[dynamicMember: dateColumn] = dateFunction
152152
},
153153
fileID: fileID,
154154
line: line,
@@ -210,8 +210,8 @@ extension Table {
210210
/// operation, and source location.
211211
/// - ifNotExists: Adds an `IF NOT EXISTS` clause to the `CREATE TRIGGER` statement.
212212
/// - dateColumn: A key path to a datetime column.
213-
/// - dateFunction: A database function that returns the current date. Include parentheses in
214-
/// string, i.e. `"customDate()"`.
213+
/// - dateFunction: A database function that returns the current date, _e.g._,
214+
/// `#sql("date('subsec'))"`.
215215
/// - fileID: The source `#fileID` associated with the trigger.
216216
/// - line: The source `#line` associated with the trigger.
217217
/// - column: The source `#column` associated with the trigger.
@@ -220,7 +220,7 @@ extension Table {
220220
_ name: String? = nil,
221221
ifNotExists: Bool = false,
222222
afterInsertTouch dateColumn: KeyPath<TableColumns, TableColumn<Self, D>>,
223-
date dateFunction: StaticString = "datetime('subsec')",
223+
date dateFunction: any QueryExpression<D> = SQLQueryExpression<D>("date('subsec')"),
224224
fileID: StaticString = #fileID,
225225
line: UInt = #line,
226226
column: UInt = #column
@@ -229,7 +229,7 @@ extension Table {
229229
name,
230230
ifNotExists: ifNotExists,
231231
afterInsertTouch: {
232-
$0[dynamicMember: dateColumn] = SQLQueryExpression("\(raw: dateFunction.description)")
232+
$0[dynamicMember: dateColumn] = dateFunction
233233
},
234234
fileID: fileID,
235235
line: line,

Tests/StructuredQueriesTests/TriggersTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ extension SnapshotTests {
117117

118118
@Test func afterUpdateTouchCustomDate() {
119119
assertQuery(
120-
Reminder.createTemporaryTrigger(afterUpdateTouch: \.updatedAt, date: "customDate()")
120+
Reminder.createTemporaryTrigger(afterUpdateTouch: \.updatedAt, date: #sql("customDate()"))
121121
) {
122122
"""
123123
CREATE TEMPORARY TRIGGER

0 commit comments

Comments
 (0)