Correct number serialization for ints.
//! Json serialisation for query engine IR
use crate::{PrismaError, PrismaResult};
-use query_core::response_ir::{Item, Response};
use indexmap::IndexMap;
use prisma_models::{GraphqlId, PrismaValue};
+use query_core::response_ir::{Item, Response};
use serde_json::{Map, Number, Value};
use std::sync::Arc;
@@ -66,7 +66,7 @@ fn serialize_list(list: Vec<Item>) -> Vec<Value> {
fn serialize_prisma_value(value: PrismaValue) -> PrismaResult<Value> {
Ok(match value {
- PrismaValue::String(x) => Value::String(x.clone()),
+ PrismaValue::String(x) => Value::String(x),
PrismaValue::Float(x) => Value::Number(match Number::from_f64(x) {
Some(num) => num,
None => return Err(PrismaError::SerializationError("`f64` number was invalid".into())),
@@ -75,24 +75,18 @@ fn serialize_prisma_value(value: PrismaValue) -> PrismaResult<Value> {
PrismaValue::DateTime(date) => Value::String(format!("{}", date.format("%Y-%m-%dT%H:%M:%S%.3fZ"))),
PrismaValue::Enum(x) => Value::String(x.as_string()),
PrismaValue::Json(x) => x,
- PrismaValue::Int(x) => Value::Number(match Number::from_f64(x as f64) {
- Some(num) => num,
- None => return Err(PrismaError::SerializationError("`f64` number was invalid".into())),
- }),
+ PrismaValue::Int(x) => Value::Number(Number::from(x)),
PrismaValue::Null => Value::Null,
PrismaValue::Uuid(x) => Value::String(x.to_hyphenated().to_string()),
- PrismaValue::GraphqlId(x) => serialize_graphql_id(&x)?,
+ PrismaValue::GraphqlId(x) => serialize_graphql_id(x)?,
PrismaValue::List(_) => unreachable!(),
})
}
-fn serialize_graphql_id(id: &GraphqlId) -> PrismaResult<Value> {
+fn serialize_graphql_id(id: GraphqlId) -> PrismaResult<Value> {
Ok(match id {
- GraphqlId::String(x) => Value::String(x.clone()),
- GraphqlId::Int(x) => Value::Number(match serde_json::Number::from_f64(*x as f64) {
- Some(num) => num,
- None => return Err(PrismaError::SerializationError("`f64` number was invalid".into())),
- }),
+ GraphqlId::String(x) => Value::String(x),
+ GraphqlId::Int(x) => Value::Number(Number::from(x)),
GraphqlId::UUID(x) => Value::String(x.to_hyphenated().to_string()),
})
}
