Skip to content

Commit e94783f

Browse files
Insert with specific unique constraint (#56)
* initial working upsert with custom key * Add insert with custom unique for all tables * update primary key version to use parameter pack * fix snapshot * wip * wip * wip * wip * wip * wip * wip --------- Co-authored-by: Stephen Celis <[email protected]>
1 parent 87ebc7c commit e94783f

26 files changed

+1024
-492
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,12 @@ and will decode data from the database using the `RawRepresentable` conformance
189189
@Row {
190190
@Column {
191191
```swift
192-
Reminder.insert(
192+
Reminder.insert {
193193
Reminder.Draft(
194194
title: "Get haircut",
195195
priority: .medium
196196
)
197-
)
197+
}
198198
```
199199
}
200200
@Column {
@@ -240,12 +240,12 @@ With that you can insert reminders with notes like so:
240240
@Row {
241241
@Column {
242242
```swift
243-
Reminder.insert(
243+
Reminder.insert {
244244
Reminder.Draft(
245245
title: "Get groceries",
246246
notes: ["Milk", "Eggs", "Bananas"]
247247
)
248-
)
248+
}
249249
```
250250
}
251251
@Column {
@@ -342,9 +342,9 @@ And StructuredQueries will take care of formatting the value for the database:
342342
@Row {
343343
@Column {
344344
```swift
345-
Reminder.insert(
345+
Reminder.insert {
346346
Reminder.Draft(date: Date())
347-
)
347+
}
348348
```
349349
}
350350
@Column {

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ capable of. See <doc:SelectStatements> for more examples of select statements, a
305305
The library provides the tools necessary to construct type-safe insert statements in SQL, including
306306
inserting an entire value into a table, inserting only a subset of rows, as well as what to do on
307307
conflicts. Using the `Reminder` data type from above, we can insert data for all of its rows using
308-
the ``Table/insert(or:_:values:onConflict:)`` method:
308+
the ``Table/insert(or:_:values:onConflict:where:doUpdate:where:)`` method:
309309

310310
@Row {
311311
@Column {
@@ -338,10 +338,11 @@ mechanism). The second trailing closure is a list of values that you want to ins
338338
and the number of columns and data type of each column must match what is specified in the first
339339
trailing closure.
340340

341-
You can provide a 3rd trailing closure to ``Table/insert(or:_:values:onConflict:)`` to describe what
342-
to do in case there is a conflict while inserting data. For example, suppose we had a unique index
343-
on the "title" column of the reminders table. Then when inserting a value with a repeated title we
344-
could resolve the conflict by appending the string `" (Copy)"` to the title:
341+
You can provide a 3rd trailing closure to
342+
``Table/insert(or:_:values:onConflict:where:doUpdate:where:)`` to describe what to do in case there
343+
is a conflict while inserting data. For example, suppose we had a unique index on the "title" column
344+
of the reminders table. Then when inserting a value with a repeated title we could resolve the
345+
conflict by appending the string `" (Copy)"` to the title:
345346

346347
@Row {
347348
@Column {

0 commit comments

Comments
 (0)