Skip to content

Commit 768be77

Browse files
committed
test(query-compiler): refresh update upsert pruning snapshots
Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 50ba2fd commit 768be77

6 files changed

Lines changed: 86 additions & 163 deletions

File tree

query-compiler/core/src/query_graph_builder/write/nested/update_nested.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::*;
22
use crate::inputs::{ReturnInput, UpdateManyRecordsSelectorsInput, UpdateRecordSelectorsInput};
3-
use crate::query_graph_builder::write::write_args_parser::WriteArgsParser;
43
use crate::query_graph_builder::write::update::UpdateManyRecordNodeOptionals;
4+
use crate::query_graph_builder::write::write_args_parser::WriteArgsParser;
55
use crate::{DataExpectation, RowSink};
66
use crate::{
77
ParsedInputValue,
@@ -94,14 +94,14 @@ pub fn nested_update(
9494
let update_args = WriteArgsParser::from(child_model, data_map)?;
9595

9696
if update_args.args.is_empty() && !update_args.nested.is_empty() {
97-
let return_node = graph.create_node(Flow::Return(Vec::new()));
97+
let return_node = graph.create_node(Flow::Return(None));
9898

9999
graph.create_edge(
100100
&find_child_records_node,
101101
&return_node,
102102
QueryGraphDependency::ProjectedDataDependency(
103103
child_model_identifier,
104-
RowSink::All(&ReturnInput),
104+
RowSink::ProjectedPlaceholder(&ReturnInput),
105105
Some(DataExpectation::non_empty_rows(
106106
MissingRelatedRecord::builder()
107107
.model(child_model)

query-compiler/core/src/query_graph_builder/write/nested/upsert_nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@ pub fn nested_upsert(
156156
)?;
157157

158158
let then_node = if is_nested_only_update {
159-
let return_node = graph.create_node(Flow::Return(Vec::new()));
159+
let return_node = graph.create_node(Flow::Return(None));
160160

161161
graph.create_edge(
162162
&read_children_node,
163163
&return_node,
164164
QueryGraphDependency::ProjectedDataDependency(
165165
child_model_identifier.clone(),
166-
RowSink::All(&ReturnInput),
166+
RowSink::ProjectedPlaceholder(&ReturnInput),
167167
Some(DataExpectation::non_empty_rows(
168168
MissingRelatedRecord::builder()
169169
.model(&child_model)

query-compiler/core/src/query_graph_builder/write/upsert.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,16 @@ pub(crate) fn upsert_record(
104104
let update_args = WriteArgsParser::from(&model, update_argument)?;
105105
let is_noop_update = update_args.args.is_empty();
106106
let update_node = if is_noop_update {
107-
let return_node = graph.create_node(Flow::Return(Vec::new()));
107+
let return_node = graph.create_node(Flow::Return(None));
108108

109109
graph.create_edge(
110110
&read_parent_records_node,
111111
&return_node,
112-
QueryGraphDependency::ProjectedDataDependency(model_id.clone(), RowSink::All(&ReturnInput), None),
112+
QueryGraphDependency::ProjectedDataDependency(
113+
model_id.clone(),
114+
RowSink::ProjectedPlaceholder(&ReturnInput),
115+
None,
116+
),
113117
)?;
114118

115119
for (relation_field, data_map) in update_args.nested {

query-compiler/query-compiler/tests/snapshots/queries__queries@nested-upsert-nested-only.json.snap

Lines changed: 37 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ transaction
2727
}
2828
let 0 = unique (query «SELECT "public"."User"."id", "public"."User"."email",
2929
"public"."User"."role"::text FROM "public"."User"
30-
WHERE "public"."User"."email" = $1 LIMIT $2 OFFSET $3»
30+
WHERE ("public"."User"."email" = $1 AND 1=1) LIMIT $2
31+
OFFSET $3»
3132
params [const(String("user.1737556028164@prisma.io")),
3233
const(BigInt(1)), const(BigInt(0))])
3334
in let 0$id = mapField id (get 0)
3435
in let 1 = query «SELECT "public"."Post"."id", "public"."Post"."userId"
35-
FROM "public"."Post" WHERE ("public"."Post"."id" = $1
36-
AND "public"."Post"."userId" IN [$2,*]) OFFSET $3»
36+
FROM "public"."Post" WHERE (("public"."Post"."id" = $1
37+
AND 1=1) AND "public"."Post"."userId" IN [$2,*]) OFFSET
38+
$3»
3739
params [const(BigInt(11)), var(0$id as Int), const(BigInt(0))]
3840
in if (rowCountNeq 0 (get 1))
3941
then let 1 = validate (get 1)
@@ -42,7 +44,8 @@ transaction
4244
in let 6 = get 1
4345
in let 7 = query «SELECT "public"."Category"."id" FROM
4446
"public"."Category" WHERE
45-
"public"."Category"."id" = $1 OFFSET $2»
47+
("public"."Category"."id" = $1 AND 1=1)
48+
OFFSET $2»
4649
params [const(BigInt(10)), const(BigInt(0))]
4750
in let 6 = unique (validate (get 6)
4851
[ rowCountNeq 0
@@ -68,7 +71,8 @@ transaction
6871
var(0$id as Int)])
6972
in let 4 = query «SELECT "public"."Category"."id" FROM
7073
"public"."Category" WHERE
71-
"public"."Category"."id" = $1 OFFSET $2»
74+
("public"."Category"."id" = $1 AND 1=1)
75+
OFFSET $2»
7276
params [const(BigInt(10)), const(BigInt(0))]
7377
in let 3 = unique (validate (get 3)
7478
[ rowCountNeq 0
@@ -87,72 +91,31 @@ transaction
8791
[ rowCountNeq 0
8892
] orRaise "MISSING_RECORD");
8993
0$id = mapField id (get 0)
90-
in rawNestedReadUnique (query «SELECT "public"."User"."id",
91-
"public"."User"."email",
92-
"public"."User"."role"::text FROM
93-
"public"."User" WHERE "public"."User"."id"
94-
= $1 LIMIT $2 OFFSET $3»
95-
params [var(0$id as Int), const(BigInt(1)),
96-
const(BigInt(0))]
97-
fields {
98-
id: 0
99-
email: 1
100-
role: 2
101-
}
102-
relations [posts on left.0 = right.2 many (query
103-
«SELECT
104-
"public"."Post"."id",
105-
"public"."Post"."title",
106-
"public"."Post"."userId"
107-
FROM
108-
"public"."Post"
109-
WHERE
110-
"public"."Post"."userId"
111-
= $1
112-
OFFSET
113-
$2»
114-
params [var(@parent$id as Int),
115-
const(BigInt(0))]
116-
fields {
117-
id: 0
118-
title: 1
119-
userId: 2
120-
}
121-
relations [categories on left.0 = right.2 many (query
122-
«SELECT
123-
"public"."Category"."id",
124-
"public"."Category"."name",
125-
"t0"."B"
126-
AS
127-
"CategoryToPost@Post"
128-
FROM
129-
"public"."Category"
130-
INNER
131-
JOIN
132-
"public"."_CategoryToPost"
133-
AS
134-
"t0"
135-
ON
136-
"t0"."A"
137-
=
138-
"public"."Category"."id"
139-
WHERE
140-
(1=1
141-
AND
142-
"t0"."B"
143-
IN
144-
[$1,*])
145-
OFFSET
146-
$2»
147-
params [var(@parent$id as Int),
148-
const(BigInt(0))]
149-
fields {
150-
id: 0
151-
name: 1
152-
})])])
153-
enums {
154-
Role: {
155-
admin: ADMIN
156-
user: USER
157-
}
158-
}
94+
in let @parent = unique (query «SELECT "public"."User"."id",
95+
"public"."User"."email",
96+
"public"."User"."role"::text FROM
97+
"public"."User" WHERE "public"."User"."id"
98+
= $1 LIMIT $2 OFFSET $3»
99+
params [var(0$id as Int), const(BigInt(1)),
100+
const(BigInt(0))])
101+
in let @parent$id = mapField id (get @parent)
102+
in join (get @parent)
103+
with (let @parent = query «SELECT "public"."Post"."id",
104+
"public"."Post"."title",
105+
"public"."Post"."userId" FROM
106+
"public"."Post" WHERE
107+
"public"."Post"."userId" = $1 OFFSET
108+
$2»
109+
params [var(@parent$id as Int),
110+
const(BigInt(0))]
111+
in let @parent$id = mapField id (get @parent)
112+
in join (get @parent)
113+
with (query «SELECT "public"."Category"."id",
114+
"public"."Category"."name", "t0"."B" AS
115+
"CategoryToPost@Post" FROM
116+
"public"."Category" INNER JOIN
117+
"public"."_CategoryToPost" AS "t0" ON
118+
"t0"."A" = "public"."Category"."id" WHERE
119+
(1=1 AND "t0"."B" IN [$1,*]) OFFSET $2»
120+
params [var(@parent$id as Int),
121+
const(BigInt(0))]) on left.(id) = right.(CategoryToPost@Post) as @nested$categories) on left.(id) = right.(userId) as @nested$posts

query-compiler/query-compiler/tests/snapshots/queries__queries@upsert-empty-update.json.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ transaction
1717
}
1818
}
1919
let 0 = query «SELECT "public"."User"."id" FROM "public"."User" WHERE
20-
"public"."User"."email" = $1 OFFSET $2»
20+
("public"."User"."email" = $1 AND 1=1) OFFSET $2»
2121
params [const(String("user.1@prisma.io")), const(BigInt(0))]
2222
in if (rowCountNeq 0 (get 0))
2323
then let 2 = get 0

0 commit comments

Comments
 (0)