-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: serialize raw results as arrays instead of object (#4939)
- Loading branch information
Showing
39 changed files
with
1,410 additions
and
850 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use serde::Serialize; | ||
use serde_json::value::RawValue; | ||
|
||
/// We are using RawJson object to prevent stringification of | ||
/// certain JSON values. Difference between this is and PrismaValue::Json | ||
/// is the following: | ||
/// | ||
/// PrismaValue::Json(r"""{"foo": "bar"}""") when serialized will produce the string "{\"foo\":\"bar\"}". | ||
/// RawJson(r"""{"foo": "bar"}""") will produce {"foo": "bar" } JSON object. | ||
/// So, it essentially would treat provided string as pre-serialized JSON fragment and not a string to be serialized. | ||
/// | ||
/// It is a wrapper of `serde_json::value::RawValue`. We don't want to use `RawValue` inside of `ArgumentValue` | ||
/// directly because: | ||
/// 1. We need `Eq` implementation | ||
/// 2. `serde_json::value::RawValue::from_string` may error and we'd like to delay handling of that error to | ||
/// serialization time | ||
#[derive(Clone, Debug, PartialEq, Eq)] | ||
pub struct RawJson { | ||
value: String, | ||
} | ||
|
||
impl RawJson { | ||
pub fn try_new(value: impl Serialize) -> serde_json::Result<Self> { | ||
Ok(Self { | ||
value: serde_json::to_string(&value)?, | ||
}) | ||
} | ||
} | ||
|
||
impl Serialize for RawJson { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
let raw_value = RawValue::from_string(self.value.to_owned()).map_err(serde::ser::Error::custom)?; | ||
raw_value.serialize(serializer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.