Skip to content

Commit f9a3e25

Browse files
committed
fix: do not wrap array parameters in arrays in push
1 parent abbfa42 commit f9a3e25

3 files changed

Lines changed: 57 additions & 4 deletions

File tree

query-compiler/query-builders/sql-query-builder/src/write.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,16 @@ pub fn build_update_and_set_query(
163163
ScalarWriteOperation::Set(rhs) => field.value(rhs, ctx).into(),
164164
ScalarWriteOperation::Add(rhs) if field.is_list() => {
165165
let e: Expression = Column::from((table.clone(), name.clone())).into();
166-
let vals: Vec<_> = match rhs {
167-
PrismaValue::List(vals) => vals.into_iter().map(|val| field.value(val, ctx)).collect(),
168-
_ => vec![field.value(rhs, ctx)],
166+
let arr = match rhs {
167+
PrismaValue::List(vals) => Value::array(vals.into_iter().map(|val| field.value(val, ctx))),
168+
PrismaValue::Placeholder(ref ph) if matches!(ph.r#type, PrismaValueType::List(_)) => {
169+
field.value(rhs, ctx)
170+
}
171+
_ => Value::array(vec![field.value(rhs, ctx)]),
169172
};
170173

171174
// Postgres only
172-
e.compare_raw("||", Value::array(vals)).into()
175+
e.compare_raw("||", arr).into()
173176
}
174177
ScalarWriteOperation::Add(rhs) => {
175178
let e: Expression<'_> = Column::from((table.clone(), name.clone())).into();
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"modelName": "DataTypes",
3+
"action": "updateOne",
4+
"query": {
5+
"arguments": {
6+
"where": {
7+
"id": ""
8+
},
9+
"data": {
10+
"intArray": {
11+
"push": {
12+
"$type": "Param",
13+
"value": {
14+
"name": "intArray",
15+
"type": "List",
16+
"inner": {
17+
"type": "Int"
18+
}
19+
}
20+
}
21+
}
22+
}
23+
},
24+
"selection": {
25+
"$scalars": true
26+
}
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
source: query-compiler/query-compiler/tests/queries.rs
3+
expression: pretty
4+
input_file: query-compiler/query-compiler/tests/data/update-push.json
5+
---
6+
dataMap {
7+
id: Bytes (id)
8+
optString: String? (optString)
9+
intArray: Int[] (intArray)
10+
}
11+
let 0 = unique (query «UPDATE "public"."DataTypes" SET "intArray" =
12+
"public"."DataTypes"."intArray" || $1 WHERE
13+
("public"."DataTypes"."id" = $2 AND 1=1) RETURNING
14+
"public"."DataTypes"."id",
15+
"public"."DataTypes"."optString",
16+
"public"."DataTypes"."intArray"»
17+
params [var(intArray as Int), const(Bytes([]))])
18+
in let 0 = validate (get 0)
19+
[ rowCountNeq 0
20+
] orRaise "MISSING_RECORD"
21+
in ();
22+
get 0

0 commit comments

Comments
 (0)