Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ refreshed with the current time immediately.

This pattern of updating a timestamp when a row changes is so common that the library comes with
a specialized tool just for that kind of trigger,
``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``:
``TemporaryTrigger/Operation/update(touch:when:)``:

@Row {
@Column {
```swift
Reminder.createTemporaryTrigger(
afterUpdateTouch: {
after: .update: {
$0.updatedAt = datetime('subsec')
}
)
Expand All @@ -72,14 +72,14 @@ a specialized tool just for that kind of trigger,

And further, the pattern of specifically updating a _timestamp_ column is so common that the library
comes with another specialized too just for that kind of trigger,
``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``:
``TemporaryTrigger/Operation/update(touch:when:)``:


@Row {
@Column {
```swift
Reminder.createTemporaryTrigger(
afterUpdateTouch: \.updatedAt
after: .update(touch: \.updatedAt)
)
```
}
Expand Down Expand Up @@ -195,11 +195,11 @@ reminder is inserted into the database with the following trigger:
- ``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:before:fileID:line:column:)``
- ``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:insteadOf:fileID:line:column:)``

### Touching records

- ``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:afterInsertTouch:fileID:line:column:)``
- ``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``

### Triggers

- ``TemporaryTrigger``

### Deprecations

- ``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:afterInsertTouch:fileID:line:column:)``
- ``StructuredQueriesCore/Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``
135 changes: 129 additions & 6 deletions Sources/StructuredQueriesSQLiteCore/Internal/Deprecations.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,123 @@
import Foundation
import StructuredQueriesCore

// NB: Deprecated after 0.22.2:

extension Table {
@available(
*,
deprecated,
message: "Prefer 'createTemporaryTrigger(after: .update(touch:))', instead"
)
Comment on lines +6 to +11
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth soft-deprecating, or is the surface minimal enough to push folks to the new APIs sooner?

public static func createTemporaryTrigger(
_ name: String? = nil,
ifNotExists: Bool = false,
afterUpdateTouch updates: (inout Updates<Self>) -> Void,
fileID: StaticString = #fileID,
line: UInt = #line,
column: UInt = #column
) -> TemporaryTrigger<Self> {
Self.createTemporaryTrigger(
name,
ifNotExists: ifNotExists,
after: .update { _, new in
Self
.where { $0.rowid.eq(new.rowid) }
.update { updates(&$0) }
},
fileID: fileID,
line: line,
column: column
)
}

@available(
*,
deprecated,
message: "Prefer 'createTemporaryTrigger(after: .update(touch:))', instead"
)
public static func createTemporaryTrigger<D: _OptionalPromotable<Date?>>(
_ name: String? = nil,
ifNotExists: Bool = false,
afterUpdateTouch dateColumn: KeyPath<TableColumns, TableColumn<Self, D>>,
date dateFunction: any QueryExpression<D> = SQLQueryExpression<D>("datetime('subsec')"),
fileID: StaticString = #fileID,
line: UInt = #line,
column: UInt = #column
) -> TemporaryTrigger<Self> {
Self.createTemporaryTrigger(
name,
ifNotExists: ifNotExists,
afterUpdateTouch: {
$0[dynamicMember: dateColumn] = dateFunction
},
fileID: fileID,
line: line,
column: column
)
}

@available(
*,
deprecated,
message: "Prefer 'createTemporaryTrigger(after: .insert(touch:))', instead"
)
public static func createTemporaryTrigger(
_ name: String? = nil,
ifNotExists: Bool = false,
afterInsertTouch updates: (inout Updates<Self>) -> Void,
fileID: StaticString = #fileID,
line: UInt = #line,
column: UInt = #column
) -> TemporaryTrigger<Self> {
Self.createTemporaryTrigger(
name,
ifNotExists: ifNotExists,
after: .insert { new in
Self
.where { $0.rowid.eq(new.rowid) }
.update { updates(&$0) }
},
fileID: fileID,
line: line,
column: column
)
}

@available(
*,
deprecated,
message: "Prefer 'createTemporaryTrigger(after: .insert(touch:))', instead"
)
public static func createTemporaryTrigger<D: _OptionalPromotable<Date?>>(
_ name: String? = nil,
ifNotExists: Bool = false,
afterInsertTouch dateColumn: KeyPath<TableColumns, TableColumn<Self, D>>,
date dateFunction: any QueryExpression<D> = SQLQueryExpression<D>("datetime('subsec')"),
fileID: StaticString = #fileID,
line: UInt = #line,
column: UInt = #column
) -> TemporaryTrigger<Self> {
Self.createTemporaryTrigger(
name,
ifNotExists: ifNotExists,
afterInsertTouch: {
$0[dynamicMember: dateColumn] = dateFunction
},
fileID: fileID,
line: line,
column: column
)
}
}

// NB: Deprecated after 0.5.1:

extension Table {
@available(
*, deprecated, message: "Use a trailing closure, instead: 'Table.insert { row }'"
*,
deprecated,
message: "Use a trailing closure, instead: 'Table.insert { row }'"
)
public static func insert(
or conflictResolution: ConflictResolution,
Expand All @@ -16,7 +128,9 @@ extension Table {
}

@available(
*, deprecated, message: "Use a trailing closure, instead: 'Table.insert { rows }'"
*,
deprecated,
message: "Use a trailing closure, instead: 'Table.insert { rows }'"
)
public static func insert(
or conflictResolution: ConflictResolution,
Expand Down Expand Up @@ -49,7 +163,10 @@ extension Table {

@available(*, deprecated, renamed: "insert(or:_:select:onConflictDoUpdate:)")
public static func insert<
V1, each V2, From, Joins
V1,
each V2,
From,
Joins
>(
or conflictResolution: ConflictResolution,
_ columns: (TableColumns) -> (TableColumn<Self, V1>, repeat TableColumn<Self, each V2>),
Expand All @@ -62,7 +179,9 @@ extension Table {

extension PrimaryKeyedTable {
@available(
*, deprecated, message: "Use a trailing closure, instead: 'Table.insert { draft }'"
*,
deprecated,
message: "Use a trailing closure, instead: 'Table.insert { draft }'"
)
public static func insert(
or conflictResolution: ConflictResolution,
Expand All @@ -73,7 +192,9 @@ extension PrimaryKeyedTable {
}

@available(
*, deprecated, message: "Use a trailing closure, instead: 'Table.insert { drafts }'"
*,
deprecated,
message: "Use a trailing closure, instead: 'Table.insert { drafts }'"
)
public static func insert(
or conflictResolution: ConflictResolution,
Expand All @@ -84,7 +205,9 @@ extension PrimaryKeyedTable {
}

@available(
*, deprecated, message: "Use a trailing closure, instead: 'Table.upsert { draft }'"
*,
deprecated,
message: "Use a trailing closure, instead: 'Table.upsert { draft }'"
)
public static func upsert(
or conflictResolution: ConflictResolution,
Expand Down
Loading