Skip to content

Commit c71961f

Browse files
committed
Fixed insert returning many for a single insert
1 parent f058f4f commit c71961f

4 files changed

Lines changed: 10 additions & 7 deletions

File tree

Sources/Compiler/Gen/SwiftLanguage.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ public struct SwiftLanguage: Language {
594594
writer.write(", tx: borrowing Transaction) async throws -> Output ")
595595

596596
writer.braces {
597-
writer.write(line: "try await execute(with: ", query.inputName, "(")
597+
writer.write(line: "try execute(with: ", query.inputName, "(")
598598
initInput()
599599
writer.write("), tx: tx)")
600600
}

Sources/Compiler/Sema/CardinalityInferrer.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,7 @@ extension CardinalityInferrer: StmtSyntaxVisitor {
102102
return cadinalityForFilter(filter, for: t.table)
103103
}
104104
case let .values(values):
105-
// VALUES (1, 2), (3, 4)
106-
if values.count > 1 {
107-
return .many
108-
}
105+
return values.count > 1 ? .many : .single
109106
}
110107

111108
return .many

Tests/CompilerTests/Compiler/CompileIsSingleResult.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ SELECT * FROM employee WHERE companyId = 1 OR userId = 1;
3434

3535
-- CHECK: MANY
3636
SELECT * FROM noPk WHERE value = ?;
37+
38+
-- CHECK: SINGLE
39+
INSERT INTO user VALUES (1, 'bob') RETURNING *;
40+
41+
-- CHECK: MANY
42+
INSERT INTO user VALUES (1, 'bob'), (2, 'joe') RETURNING *;

Tests/CompilerTests/Gen/Swift.output

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ extension Query where Input == InsertUserInput {
417417
}
418418

419419
func execute(id: Int, firstName: String, lastName: String, preference: Bool?, favoriteNumber: Int?, randomValue: SQLAny?, bornOn: Date?, tx: borrowing Transaction) async throws -> Output {
420-
try await execute(with: InsertUserInput(id: id, firstName: firstName, lastName: lastName, preference: preference, favoriteNumber: favoriteNumber, randomValue: randomValue, bornOn: bornOn), tx: tx)
420+
try execute(with: InsertUserInput(id: id, firstName: firstName, lastName: lastName, preference: preference, favoriteNumber: favoriteNumber, randomValue: randomValue, bornOn: bornOn), tx: tx)
421421
}
422422

423423
func observe(id: Int, firstName: String, lastName: String, preference: Bool?, favoriteNumber: Int?, randomValue: SQLAny?, bornOn: Date?) -> any QueryObservation<Output> {
@@ -436,7 +436,7 @@ extension Query where Input == SelectUserWithManyInputsInput {
436436
}
437437

438438
func execute(id: Int, firstName: String, tx: borrowing Transaction) async throws -> Output {
439-
try await execute(with: SelectUserWithManyInputsInput(id: id, firstName: firstName), tx: tx)
439+
try execute(with: SelectUserWithManyInputsInput(id: id, firstName: firstName), tx: tx)
440440
}
441441

442442
func observe(id: Int, firstName: String) -> any QueryObservation<Output> {

0 commit comments

Comments
 (0)