Skip to content

Commit

Permalink
fix(driver-adapters): fix Bytes issues for PlanetScale (#4695)
Browse files Browse the repository at this point in the history
* feat: bump @planetscale/database to 1.15.0

* test(driver-adapters): fix prisma/team-orm#687, DRIVER_ADAPTERS_BRANCH=feat/update-planetscale

* chore: fix typo, DRIVER_ADAPTERS_BRANCH=feat/update-planetscale

* [skip ci] chore: fix indentation
  • Loading branch information
jkomyno authored Feb 7, 2024
1 parent 6ba3e3d commit 893c63a
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,87 @@ use query_engine_tests::*;
mod bytes {
use query_engine_tests::{run_query, EngineProtocol, Runner};

#[test_suite]
mod issue_687 {
fn schema_common() -> String {
let schema = indoc! {
r#"model Parent {
#id(id, Int, @id)
children Child[]
}
model Child {
#id(childId, Int, @id)
parentId Int?
parent Parent? @relation(fields: [parentId], references: [id])
bytes Bytes
}
"#
};

schema.to_owned()
}

async fn create_common_children(runner: &Runner) -> TestResult<()> {
create_child(
&runner,
r#"{
childId: 1,
bytes: "AQID",
}"#,
)
.await?;

create_child(
&runner,
r#"{
childId: 2,
bytes: "FDSF"
}"#,
)
.await?;

create_parent(
&runner,
r#"{ id: 1, children: { connect: [{ childId: 1 }, { childId: 2 }] } }"#,
)
.await?;

Ok(())
}

#[connector_test(schema(schema_common))]
async fn common_types(runner: Runner) -> TestResult<()> {
create_common_children(&runner).await?;

insta::assert_snapshot!(
run_query!(&runner, r#"{ findManyParent { id children { childId bytes } } }"#),
@r###"{"data":{"findManyParent":[{"id":1,"children":[{"childId":1,"bytes":"AQID"},{"childId":2,"bytes":"FDSF"}]}]}}"###
);

Ok(())
}

async fn create_child(runner: &Runner, data: &str) -> TestResult<()> {
runner
.query(format!("mutation {{ createOneChild(data: {}) {{ childId }} }}", data))
.await?
.assert_success();
Ok(())
}

async fn create_parent(runner: &Runner, data: &str) -> TestResult<()> {
runner
.query(format!("mutation {{ createOneParent(data: {}) {{ id }} }}", data))
.await?
.assert_success();
Ok(())
}
}

#[connector_test]
async fn read_one(runner: Runner) -> TestResult<()> {
create_test_data(&runner).await?;
Expand All @@ -14,7 +95,7 @@ mod bytes {

insta::assert_snapshot!(
res,
@r###"{"data":{"findUniqueTestModel":{"bytes":"AQID"}}}"###
@r###"{"data":{"findUniqueTestModel":{"bytes":"FSDF"}}}"###
);
}
EngineProtocol::Json => {
Expand All @@ -37,7 +118,7 @@ mod bytes {

insta::assert_snapshot!(
res.to_string(),
@r###"{"data":{"findUniqueTestModel":{"bytes":{"$type":"Bytes","value":"AQID"}}}}"###
@r###"{"data":{"findUniqueTestModel":{"bytes":{"$type":"Bytes","value":"FSDF"}}}}"###
);
}
}
Expand All @@ -55,7 +136,7 @@ mod bytes {

insta::assert_snapshot!(
res,
@r###"{"data":{"findManyTestModel":[{"bytes":"AQID"},{"bytes":"dGVzdA=="},{"bytes":null}]}}"###
@r###"{"data":{"findManyTestModel":[{"bytes":"FSDF"},{"bytes":"dGVzdA=="},{"bytes":null}]}}"###
);
}
query_engine_tests::EngineProtocol::Json => {
Expand All @@ -75,7 +156,7 @@ mod bytes {

insta::assert_snapshot!(
res.to_string(),
@r###"{"data":{"findManyTestModel":[{"bytes":{"$type":"Bytes","value":"AQID"}},{"bytes":{"$type":"Bytes","value":"dGVzdA=="}},{"bytes":null}]}}"###
@r###"{"data":{"findManyTestModel":[{"bytes":{"$type":"Bytes","value":"FSDF"}},{"bytes":{"$type":"Bytes","value":"dGVzdA=="}},{"bytes":null}]}}"###
);
}
}
Expand All @@ -84,7 +165,7 @@ mod bytes {
}

async fn create_test_data(runner: &Runner) -> TestResult<()> {
create_row(runner, r#"{ id: 1, bytes: "AQID" }"#).await?;
create_row(runner, r#"{ id: 1, bytes: "FSDF" }"#).await?;
create_row(runner, r#"{ id: 2, bytes: "dGVzdA==" }"#).await?;
create_row(runner, r#"{ id: 3 }"#).await?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,12 @@ mod scalar_relations {
schema.to_owned()
}

// TODO: fix https://github.com/prisma/team-orm/issues/684, https://github.com/prisma/team-orm/issues/687 and unexclude DAs
// TODO: fix https://github.com/prisma/team-orm/issues/684 and unexclude DAs.
// On Pg/Neon, this currently fails with "P2023":
// `Inconsistent column data: Unexpected conversion failure for field Child.bInt from Number(14324324234324.0) to BigInt`.
#[connector_test(
schema(schema_common),
exclude(
Postgres("pg.js", "neon.js", "pg.js.wasm", "neon.js.wasm"),
Vitess("planetscale.js", "planetscale.js.wasm")
)
exclude(Postgres("pg.js", "neon.js", "pg.js.wasm", "neon.js.wasm"))
)]
async fn common_types(runner: Runner) -> TestResult<()> {
create_common_children(&runner).await?;
Expand Down
2 changes: 1 addition & 1 deletion query-engine/driver-adapters/executor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"dependencies": {
"@libsql/client": "0.3.6",
"@neondatabase/serverless": "0.7.2",
"@planetscale/database": "1.14.0",
"@planetscale/database": "1.15.0",
"query-engine-wasm-latest": "npm:@prisma/query-engine-wasm@latest",
"query-engine-wasm-baseline": "npm:@prisma/[email protected]",
"@prisma/adapter-libsql": "workspace:*",
Expand Down

0 comments on commit 893c63a

Please sign in to comment.