Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix result expression for grouped statements #4378

Merged
merged 3 commits into from
Jul 17, 2023
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 @@ -272,6 +272,13 @@ abstract class QueryGenerator(
}
}

// Extract value from the result of a grouped statement in async,
// because the transaction is put in an QueryResult.AsyncValue block.
if (generateAsync && isNamedQuery && query.statement is SqlDelightStmtClojureStmtList) {
binder += "%L"
arguments.add(".await()")
}

val statementId = if (needsFreshStatement) CodeBlock.of("null") else CodeBlock.of("%L", id)

if (isNamedQuery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ class AsyncSelectQueryTypeTest {
| |SELECT value
| | FROM data
| | WHERE id = last_insert_rowid()
| ""${'"'}.trimMargin(), mapper, 0)
| ""${'"'}.trimMargin(), mapper, 0).await()
| }
| }
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ insertDog:
INSERT INTO dog
VALUES (?, ?, DEFAULT, ?);

insertDogAndReturnAll {
INSERT INTO dog
VALUES (?, ?, DEFAULT, ?);

SELECT * FROM dog;
}

selectDogs:
SELECT *
FROM dog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class MySqlTest {
)
}

@Test
fun insertAndReturn() = runTest { database ->
val all = database.dogQueries.insertDogAndReturnAll("Tilda", "Pomeranian", null)
assertThat(all.awaitAsList())
.containsExactly(
Dog(
name = "Tilda",
breed = "Pomeranian",
is_good = true,
age = null,
),
)
}

@Test
fun simpleSelectWithIn() = runTest { database ->
with(database) {
Expand Down