Skip to content

fix: serialize uint32 as JS numbers #3467

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 @@ -196,6 +196,64 @@ mod typed_output {
Ok(())
}

fn schema_native_types_pg() -> String {
let schema = indoc! {
r#"model TestModel {
#id(id, Int, @id)
oid Int? @test.Oid
}"#
};

schema.to_owned()
}

#[connector_test(schema(schema_native_types_pg), only(Postgres))]
async fn native_types_pg(runner: Runner) -> TestResult<()> {
create_row(
&runner,
r#"{
id: 1,
oid: 4294967295
}"#,
)
.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": [
{
"id": {
"prisma__type": "int",
"prisma__value": 1
},
"oid": {
"prisma__type": "uint32",
"prisma__value": 4294967295
}
},
{
"id": {
"prisma__type": "int",
"prisma__value": 2
},
"oid": {
"prisma__type": "null",
"prisma__value": null
}
}
]
}
}
"###
);

Ok(())
}

fn schema_mysql() -> String {
let schema = indoc! {
r#"model TestModel {
Expand Down Expand Up @@ -341,6 +399,53 @@ mod typed_output {
Ok(())
}

fn schema_uint() -> String {
let schema = indoc! {
r#"model TestModel {
#id(id, Int, @id)
uint Int @test.UnsignedInt
}"#
};

schema.to_owned()
}

#[connector_test(schema(schema_uint), only(MySql))]
async fn uint_as_int_mysql(runner: Runner) -> TestResult<()> {
create_row(
&runner,
r#"{
id: 1,
uint: 4294967295,
}"#,
)
.await?;

insta::assert_snapshot!(
run_query_pretty!(&runner, fmt_query_raw(r#"SELECT * FROM TestModel;"#, vec![])),
@r###"
{
"data": {
"queryRaw": [
{
"id": {
"prisma__type": "int",
"prisma__value": 1
},
"uint": {
"prisma__type": "uint32",
"prisma__value": 4294967295
}
}
]
}
}
"###
);

Ok(())
}

#[connector_test(schema(schema_mysql), only(MySql("mariadb")))]
async fn all_scalars_mariadb(runner: Runner) -> TestResult<()> {
create_row(
Expand Down
1 change: 1 addition & 0 deletions query-engine/connectors/sql-query-connector/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub fn to_prisma_value(quaint_value: Value<'_>) -> crate::Result<PrismaValue> {
let val = match quaint_value {
Value::Int32(i) => i.map(|i| PrismaValue::Int(i as i64)).unwrap_or(PrismaValue::Null),
Value::Int64(i) => i.map(PrismaValue::Int).unwrap_or(PrismaValue::Null),
Value::UnsignedInt32(u) => u.map(|u| PrismaValue::Int(u as i64)).unwrap_or(PrismaValue::Null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

94% of developers fix this issue

compiler-message: error[E0599]: no variant or associated item named UnsignedInt32 found for enum quaint::Value in the current scope
--> query-engine/connectors/sql-query-connector/src/value.rs:11:16
|
11 | Value::UnsignedInt32(u) => u.map(|u| PrismaValue::Int(u as i64)).unwrap_or(PrismaValue::Null),
| ^^^^^^^^^^^^^ variant or associated item not found in quaint::Value<'_>


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

Value::Float(Some(f)) => match f {
f if f.is_nan() => {
return Err(ConversionFailure {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl<'a> IntoTypedJsonExtension for quaint::Value<'a> {
let type_name = match self {
quaint::Value::Int32(_) => "int",
quaint::Value::Int64(_) => "bigint",
quaint::Value::UnsignedInt32(_) => "uint32",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

94% of developers fix this issue

compiler-message: error[E0599]: no variant or associated item named UnsignedInt32 found for enum quaint::Value in the current scope
--> query-engine/connectors/sql-query-connector/src/value_ext.rs:17:28
|
17 | quaint::Value::UnsignedInt32(_) => "uint32",
| ^^^^^^^^^^^^^ variant or associated item not found in quaint::Value<'_>


ℹ️ Learn about @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.


Was this a good recommendation?
[ 🙁 Not relevant ] - [ 😕 Won't fix ] - [ 😑 Not critical, will fix ] - [ 🙂 Critical, will fix ] - [ 😊 Critical, fixing now ]

quaint::Value::Float(_) => "float",
quaint::Value::Double(_) => "double",
quaint::Value::Text(_) => "string",
Expand Down