Skip to content

Commit

Permalink
fix: convert small integers of unknown type into i32 for driver adapt…
Browse files Browse the repository at this point in the history
…ers (#5094)

* fix: convert small integers of unknown type into i32 for driver adapters

* DRIVER_ADAPTERS_BRANCH=feat/sqlite-json chore: re-trigger CI
  • Loading branch information
jacek-prisma authored Dec 19, 2024
1 parent acc7a89 commit 4c6d8d3
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,86 @@ mod typed_output {
Ok(())
}

#[connector_test(schema(schema_sqlite), only(Sqlite("cfd1")))]
async fn all_scalars_cfd1(runner: Runner) -> TestResult<()> {
create_row(
&runner,
r#"{
id: 1,
string: "str",
int: 42,
bInt: 92233720368,
float: 1.5432,
bytes: "AQID",
bool: true,
dt: "1900-10-10T01:10:10.001Z",
dec: "123.45678910",
}"#,
)
.await?;
create_row(&runner, r#"{ id: 2 }"#).await?;

insta::assert_snapshot!(
run_query_pretty!(&runner, fmt_query_raw(r#"SELECT * FROM TestModel;"#, vec![])),
@r###"
{
"data": {
"queryRaw": {
"columns": [
"id",
"string",
"int",
"bInt",
"float",
"bytes",
"bool",
"dt",
"dec"
],
"types": [
"int",
"string",
"int",
"bigint",
"double",
"bytes",
"int",
"datetime",
"double"
],
"rows": [
[
1,
"str",
42,
"92233720368",
1.5432,
"AQID",
1,
"1900-10-10T01:10:10.001+00:00",
123.4567891
],
[
2,
null,
null,
null,
null,
null,
null,
null,
null
]
]
}
}
}
"###
);

Ok(())
}

#[connector_test(schema(generic), only(Mysql))]
async fn unknown_type_mysql(runner: Runner) -> TestResult<()> {
insta::assert_snapshot!(
Expand Down
6 changes: 5 additions & 1 deletion query-engine/driver-adapters/src/conversion/js_to_quaint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ pub fn js_value_to_quaint(
ColumnType::UnknownNumber => match json_value {
serde_json::Value::Number(n) => n
.as_i64()
.map(QuaintValue::int64)
.map(|i| {
i32::try_from(i)
.map(QuaintValue::int32)
.unwrap_or_else(|_| QuaintValue::int64(i))
})
.or(n.as_f64().map(QuaintValue::double))
.ok_or(conversion_error!(
"number must be an i64 or f64 in column '{column_name}', got {n}"
Expand Down

0 comments on commit 4c6d8d3

Please sign in to comment.