Skip to content

Commit c642439

Browse files
committed
More extensions
1 parent 7570da9 commit c642439

3 files changed

Lines changed: 22 additions & 2 deletions

File tree

Sources/Compiler/Gen/SwiftLanguage.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ public struct SwiftLanguage: Language {
576576
extensionOn("Query") {
577577
self.writer.write("Input == ", query.inputName)
578578
} builder: {
579+
// Execute no tx
579580
writer.write("func execute(")
580581
writeInput()
581582
writer.write(") async throws -> Output ")
@@ -586,6 +587,19 @@ public struct SwiftLanguage: Language {
586587
writer.write("))")
587588
}
588589

590+
// Execute with tx
591+
writer.blankLine()
592+
writer.write(line: "func execute(")
593+
writeInput()
594+
writer.write(", tx: borrowing Transaction) async throws -> Output ")
595+
596+
writer.braces {
597+
writer.write(line: "try await execute(with: ", query.inputName, "(")
598+
initInput()
599+
writer.write("), tx: tx)")
600+
}
601+
602+
// Observe
589603
writer.blankLine()
590604
writer.write(line: "func observe(")
591605
writeInput()

Tests/CompilerTests/Gen/Swift.output

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ extension Query where Input == InsertUserInput {
416416
try await execute(with: InsertUserInput(id: id, firstName: firstName, lastName: lastName, preference: preference, favoriteNumber: favoriteNumber, randomValue: randomValue, bornOn: bornOn))
417417
}
418418

419+
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)
421+
}
422+
419423
func observe(id: Int, firstName: String, lastName: String, preference: Bool?, favoriteNumber: Int?, randomValue: SQLAny?, bornOn: Date?) -> any QueryObservation<Output> {
420424
observe(with: InsertUserInput(id: id, firstName: firstName, lastName: lastName, preference: preference, favoriteNumber: favoriteNumber, randomValue: randomValue, bornOn: bornOn))
421425
}
@@ -431,6 +435,10 @@ extension Query where Input == SelectUserWithManyInputsInput {
431435
try await execute(with: SelectUserWithManyInputsInput(id: id, firstName: firstName))
432436
}
433437

438+
func execute(id: Int, firstName: String, tx: borrowing Transaction) async throws -> Output {
439+
try await execute(with: SelectUserWithManyInputsInput(id: id, firstName: firstName), tx: tx)
440+
}
441+
434442
func observe(id: Int, firstName: String) -> any QueryObservation<Output> {
435443
observe(with: SelectUserWithManyInputsInput(id: id, firstName: firstName))
436444
}

Tests/CompilerTests/GenTests.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ struct GenTests {
2424
schema: compiler.schema
2525
)
2626

27-
print(rawOutput)
28-
2927
for diagnostics in migrations.1 {
3028
Issue.record(diagnostics)
3129
}

0 commit comments

Comments
 (0)