diff --git a/psl/builtin-connectors/src/cockroach_datamodel_connector.rs b/psl/builtin-connectors/src/cockroach_datamodel_connector.rs index aa9d9ae27446..7b2dabfe7c27 100644 --- a/psl/builtin-connectors/src/cockroach_datamodel_connector.rs +++ b/psl/builtin-connectors/src/cockroach_datamodel_connector.rs @@ -323,14 +323,7 @@ impl Connector for CockroachDatamodelConnector { CockroachType::Timestamp(_) => crate::utils::parse_timestamp(str), CockroachType::Date => crate::utils::parse_date(str), CockroachType::Time(_) => crate::utils::parse_time(str), - CockroachType::Timetz(_) => { - // We currently don't support time with timezone. - // We strip the timezone information and parse it as a time. - // This is inline with what Quaint does already. - let time_without_tz = str.split("+").next().unwrap(); - - crate::utils::parse_time(time_without_tz) - } + CockroachType::Timetz(_) => crate::utils::parse_timetz(str), _ => unreachable!(), }, None => crate::utils::parse_timestamptz(str), diff --git a/psl/builtin-connectors/src/postgres_datamodel_connector.rs b/psl/builtin-connectors/src/postgres_datamodel_connector.rs index c16b559a8253..cccd9ad3f865 100644 --- a/psl/builtin-connectors/src/postgres_datamodel_connector.rs +++ b/psl/builtin-connectors/src/postgres_datamodel_connector.rs @@ -583,11 +583,7 @@ impl Connector for PostgresDatamodelConnector { Timestamp(_) => crate::utils::parse_timestamp(str), Date => crate::utils::parse_date(str), Time(_) => crate::utils::parse_time(str), - Timetz(_) => { - let time_without_tz = str.split('+').next().unwrap(); - - crate::utils::parse_time(time_without_tz) - } + Timetz(_) => crate::utils::parse_timetz(str), _ => unreachable!(), }, None => crate::utils::parse_timestamptz(str), diff --git a/psl/builtin-connectors/src/utils.rs b/psl/builtin-connectors/src/utils.rs index 188abe850667..6e4c1298aeb4 100644 --- a/psl/builtin-connectors/src/utils.rs +++ b/psl/builtin-connectors/src/utils.rs @@ -29,6 +29,15 @@ pub(crate) fn parse_time(str: &str) -> Result, chrono::Par .map(DateTime::::from) } +pub(crate) fn parse_timetz(str: &str) -> Result, chrono::ParseError> { + // We currently don't support time with timezone. + // We strip the timezone information and parse it as a time. + // This is inline with what Quaint does already. + let time_without_tz = str.split('+').next().unwrap(); + + parse_time(time_without_tz) +} + pub(crate) fn parse_money(str: &str) -> Result { // We strip out the currency sign from the string. BigDecimal::from_str(&str[1..]).map(|bd| bd.normalized()) diff --git a/query-engine/connectors/sql-query-connector/src/database/operations/coerce.rs b/query-engine/connectors/sql-query-connector/src/database/operations/coerce.rs index c03c0b1042d4..8af1f8d2ba08 100644 --- a/query-engine/connectors/sql-query-connector/src/database/operations/coerce.rs +++ b/query-engine/connectors/sql-query-connector/src/database/operations/coerce.rs @@ -100,10 +100,10 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel serde_json::Value::Bool(b) => Ok(PrismaValue::Boolean(b)), serde_json::Value::Number(n) => match sf.type_identifier() { TypeIdentifier::Int => Ok(PrismaValue::Int(n.as_i64().ok_or_else(|| { - build_conversion_error(&sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier())) + build_conversion_error(sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier())) })?)), TypeIdentifier::BigInt => Ok(PrismaValue::BigInt(n.as_i64().ok_or_else(|| { - build_conversion_error(&sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier())) + build_conversion_error(sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier())) })?)), TypeIdentifier::Float | TypeIdentifier::Decimal => { let bd = n @@ -111,13 +111,13 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel .and_then(BigDecimal::from_f64) .map(|bd| bd.normalized()) .ok_or_else(|| { - build_conversion_error(&sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier())) + build_conversion_error(sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier())) })?; Ok(PrismaValue::Float(bd)) } _ => Err(build_conversion_error( - &sf, + sf, &format!("Number({n})"), &format!("{:?}", sf.type_identifier()), )), @@ -128,7 +128,7 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel TypeIdentifier::DateTime => { let res = sf.coerce_json_datetime(&s).map_err(|err| { build_conversion_error_with_reason( - &sf, + sf, &format!("String({s})"), &format!("{:?}", sf.type_identifier()), &err.to_string(), @@ -140,7 +140,7 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel TypeIdentifier::Decimal => { let res = sf.coerce_json_decimal(&s).map_err(|err| { build_conversion_error_with_reason( - &sf, + sf, &format!("String({s})"), &format!("{:?}", sf.type_identifier()), &err.to_string(), @@ -151,7 +151,7 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel } TypeIdentifier::UUID => Ok(PrismaValue::Uuid(uuid::Uuid::parse_str(&s).map_err(|err| { build_conversion_error_with_reason( - &sf, + sf, &format!("String({s})"), &format!("{:?}", sf.type_identifier()), &err.to_string(), @@ -161,7 +161,7 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel // We skip the first two characters because there's the \x prefix. let bytes = hex::decode(&s[2..]).map_err(|err| { build_conversion_error_with_reason( - &sf, + sf, &format!("String({s})"), &format!("{:?}", sf.type_identifier()), &err.to_string(), @@ -171,7 +171,7 @@ pub(crate) fn coerce_json_scalar_to_pv(value: serde_json::Value, sf: &ScalarFiel Ok(PrismaValue::Bytes(bytes)) } _ => Err(build_conversion_error( - &sf, + sf, &format!("String({s})"), &format!("{:?}", sf.type_identifier()), )),