Skip to content

Commit

Permalink
Make ScalarValue::Float double precision
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhoule committed Mar 10, 2020
1 parent df8b0d4 commit 97e8021
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ fn parse_bool(value: &str) -> Option<bool> {

static RE_FLOAT: Lazy<Regex> = Lazy::new(|| Regex::new(r"^'?([^']+)'?$").expect("compile regex"));

fn parse_float(value: &str) -> Option<f32> {
fn parse_float(value: &str) -> Option<f64> {
debug!("Parsing float '{}'", value);
let rslt = RE_FLOAT.captures(value);
if rslt.is_none() {
Expand All @@ -473,7 +473,7 @@ fn parse_float(value: &str) -> Option<f32> {

let captures = rslt.expect("get captures");
let num_str = captures.get(1).expect("get capture").as_str();
let num_rslt = num_str.parse::<f32>();
let num_rslt = num_str.parse::<f64>();
match num_rslt {
Ok(num) => Some(num),
Err(_) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl ToString for ScalarType {
#[derive(Debug, PartialEq, Clone, Serialize, Deserialize)]
pub enum ScalarValue {
Int(i32),
Float(f32),
Float(f64),
Decimal(f64),
Boolean(bool),
String(String),
Expand Down
6 changes: 3 additions & 3 deletions libs/datamodel/core/src/common/value_validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ impl ValueValidator {
}

/// Tries to convert the wrapped value to a Prisma Float.
pub fn as_float(&self) -> Result<f32, DatamodelError> {
pub fn as_float(&self) -> Result<f64, DatamodelError> {
match &self.value {
ast::Expression::NumericValue(value, _) => self.wrap_error_from_result(value.parse::<f32>(), "numeric"),
ast::Expression::Any(value, _) => self.wrap_error_from_result(value.parse::<f32>(), "numeric"),
ast::Expression::NumericValue(value, _) => self.wrap_error_from_result(value.parse::<f64>(), "numeric"),
ast::Expression::Any(value, _) => self.wrap_error_from_result(value.parse::<f64>(), "numeric"),
_ => Err(self.construct_type_mismatch_error("numeric")),
}
}
Expand Down
10 changes: 0 additions & 10 deletions libs/prisma-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,6 @@ impl TryFrom<f64> for PrismaValue {

fn try_from(f: f64) -> PrismaValueResult<PrismaValue> {
Decimal::from_f64(f)
.map(|d| PrismaValue::Float(d))
.ok_or(ConversionFailure::new("f32", "Decimal"))
}
}

impl TryFrom<f32> for PrismaValue {
type Error = ConversionFailure;

fn try_from(f: f32) -> PrismaValueResult<PrismaValue> {
Decimal::from_f32(f)
.map(|d| PrismaValue::Float(d))
.ok_or(ConversionFailure::new("f64", "Decimal"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ async fn postgres_types_roundtrip(api: &TestApi) -> TestResult {
Ok(())
}

#[test_each_connector(tags("postgres"))]
#[test_each_connector(tags("postgres"), log = "debug")]
async fn small_float_values_must_work(api: &TestApi) -> TestResult {
let schema = indoc! {
r#"
Expand Down

0 comments on commit 97e8021

Please sign in to comment.