Skip to content

Commit 6ade611

Browse files
committed
wip
1 parent b4ce72c commit 6ade611

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

Sources/StructuredQueries/Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public macro Column(
4646
type: "ColumnMacro"
4747
)
4848

49-
/// Tells Structured Queries not to consider the annotated property a column of the table
49+
/// Tells StructuredQueries not to consider the annotated property a column of the table.
5050
///
5151
/// Like SwiftData's `@Transient` macro, but for SQL.
5252
@attached(peer)

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

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ This will make it so that anytime a reminder is updated in the database its `upd
4444
refreshed with the current time immediately.
4545

4646
This pattern of updating a timestamp when a row changes is so common that the library comes with
47-
a specialized tool just for that kind of trigger, ``Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``:
47+
a specialized tool just for that kind of trigger,
48+
``Table/createTemporaryTrigger(_:ifNotExists:afterUpdateTouch:fileID:line:column:)``:
4849

4950
@Row {
5051
@Column {
@@ -97,28 +98,27 @@ comes with another specialized too just for that kind of trigger,
9798
}
9899
}
99100

100-
101101
### More types of triggers
102102

103-
There are 3 kinds of triggers depending on the event being listened for in the database: an
104-
update trigger, an insert trigger, and a deletion trigger. For each of these kinds of triggers one
105-
can perform 4 kinds of actions: a select, insert, update or delete. All 12 combinations of these
106-
kinds of triggers are supported by the library.
103+
There are 3 kinds of triggers depending on the event being listened for in the database: inserts,
104+
updates, and deletes. For each of these kinds of triggers one can perform 4 kinds of actions: a
105+
select, insert, update, or delete. All 12 combinations of these kinds of triggers are supported by
106+
the library.
107107

108-
> Note: Technically SQLite supports "BEFORE" triggers and "AFTER" triggers, but the documentation
109-
> recommends against using "BEFORE" triggers as it can lead to undefined behavior. Therefore
110-
> Structured Queries does not expose "BEFORE" triggers in its API. If you want to go against the
111-
> recommendations of SQLite and create a "BEFORE" trigger, you can always write a trigger as a
112-
> SQL string (see <docs:SafeSQLStrings> for more info).
108+
> Note: Technically SQLite supports `BEFORE` triggers and `AFTER` triggers, but the documentation
109+
> recommends against using `BEFORE` triggers as it can lead to undefined behavior. Therefore
110+
> StructuredQueries does not expose `BEFORE` triggers in its API. If you want to go against the
111+
> recommendations of SQLite and create a `BEFORE` trigger, you can always write a trigger as a SQL
112+
> string (see <docs:SafeSQLStrings> for more info).
113113
114114
Here are a few examples to show you the possibilities with triggers:
115115

116116
#### Non-empty tables
117117

118118
One can use triggers to enforce that a table is never fully emptied out. For example, suppose you
119-
want to make sure that the "remindersLists" table always has at least one row. Then one can
120-
use an "AFTER DELETE" trigger with an "INSERT" action to insert a stub reminders list when it
121-
detects the last list was deleted:
119+
want to make sure that the `remindersLists` table always has at least one row. Then one can use an
120+
`AFTER DELETE` trigger with an `INSERT` action to insert a stub reminders list when it detects the
121+
last list was deleted:
122122

123123
@Row {
124124
@Column {
@@ -153,15 +153,14 @@ detects the last list was deleted:
153153

154154
#### Invoke Swift code from triggers
155155

156-
One can use triggers with a "SELECT" action to invoke Swift code when an event occurs in your
156+
One can use triggers with a `SELECT` action to invoke Swift code when an event occurs in your
157157
database. For example, suppose you want to execute a Swift function a new reminder is inserted
158158
into the database. First you must register the function with SQLite and that depends on what
159-
SQLite driver you are using ([here][grdb-add-function] is how to do it in GRDB). Suppose we
160-
registered a function called `didInsertReminder`, and further suppose it takes one argument
161-
of the ID of the newly inserted reminder.
159+
SQLite driver you are using ([here][grdb-add-function] is how to do it in GRDB).
162160

163-
Then one can invoke this function whenever a reminder is inserted into the database with the
164-
following trigger:
161+
Suppose we registered a function called `didInsertReminder`, and further suppose it takes one
162+
argument of the ID of the newly inserted reminder. Then one can invoke this function whenever a
163+
reminder is inserted into the database with the following trigger:
165164

166165
[grdb-add-function]: https://swiftpackageindex.com/groue/grdb.swift/v7.5.0/documentation/grdb/database/add(function:)
167166

0 commit comments

Comments
 (0)