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

driver-adapters: convert Decimals to Strings when calling JS #4408

Merged
merged 4 commits into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -198,6 +198,35 @@ mod mysql {
Ok(())
}

fn schema_decimal_vitess() -> String {
let schema = indoc! {
r#"model Model {
#id(id, String, @id, @default(cuid()))
decLarge Decimal @test.Decimal(20, 10)
}"#
};

schema.to_owned()
}

#[connector_test(only(Vitess), schema(schema_decimal_vitess))]
async fn native_decimal_vitess_precision(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
run_query!(&runner, r#"mutation {
createOneModel(
data: {
decLarge: "131603421.38724228"
}
) {
decLarge
}
}"#),
@r###"{"data":{"createOneModel":{"decLarge":"131603421.38724228"}}}"###
);

Ok(())
}

fn schema_string() -> String {
let schema = indoc! {
r#"model Model {
Expand Down
7 changes: 2 additions & 5 deletions query-engine/driver-adapters/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,8 @@ pub fn values_to_js_args(values: &[quaint::Value<'_>]) -> serde_json::Result<Vec
Some(bytes) => JSArg::Buffer(bytes.to_vec()),
None => JsonValue::Null.into(),
},
quaint_value @ quaint::ValueType::Numeric(bd) => match bd {
Some(bd) => match bd.to_string().parse::<f64>() {
Ok(double) => JSArg::from(JsonValue::from(double)),
Err(_) => JSArg::from(JsonValue::from(quaint_value.clone())),
},
quaint::ValueType::Numeric(bd) => match bd {
Some(bd) => JSArg::RawString(bd.to_string()),
SevInf marked this conversation as resolved.
Show resolved Hide resolved
None => JsonValue::Null.into(),
},
quaint::ValueType::Array(Some(items)) => JSArg::Array(values_to_js_args(items)?),
Expand Down
4 changes: 0 additions & 4 deletions query-engine/driver-adapters/src/conversion/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ pub fn values_to_js_args(values: &[quaint::Value<'_>]) -> serde_json::Result<Vec
Some(bytes) => JSArg::Buffer(bytes.to_vec()),
None => JsonValue::Null.into(),
},
(quaint::ValueType::Numeric(bd), _) => match bd {
Some(bd) => JSArg::RawString(bd.to_string()),
None => JsonValue::Null.into(),
},
(quaint::ValueType::Array(Some(items)), _) => JSArg::Array(values_to_js_args(items)?),
(quaint_value, _) => JSArg::from(JsonValue::from(quaint_value.clone())),
};
Expand Down
Loading